Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * and expected output.
- *
- * If you have node installed, all you need to do to test
- * your code is run: `node tripleThreat.js`. If you see errors,
- * it is because the tests below did not pass. Once the
- * tests do pass, you will see a log of `Success!`
- *
- * YOUR CODE BELOW HERE
- ********************************/
- function tripleThreat(array) {
- var isTrip;
- var numChain = 1;
- var currVal;
- var nextExpected;
- var nextVal;
- for (i = 0; i < array.length - 1; i++){
- currVal = array[i];
- nextVal = array[i + 1];
- nextExpected = currVal + 1;
- if(nextVal === nextExpected){
- numChain++;
- if(numChain === 3){
- isTrip = true;
- return isTrip;
- }
- }else{
- numChain = 1;
- }
- //currVal = array[i];
- //currVal = array[i];
- }
- return false;
- }
- /********************************
- * YOUR CODE ABOVE HERE
- ********************************/
- assert.equal(
- tripleThreat([1, 4, 5, 6, 2]),
- true
- );
- assert.equal(
- tripleThreat([1, 2, 3]),
- true
- );
- assert.equal(
- tripleThreat([1, 2, 4, 5, 7, 6, 5, 6, 7, 6]),
- true
- );
- assert.equal(
- tripleThreat([1, 2, 4, 5, 7, 6, 5, 7, 7, 6]),
- false
- );
- assert.equal(
- tripleThreat([1,2]),
- false
- );
- assert.equal(
- tripleThreat([10, 9, 8, -100, -99, -98, 100]),
- true
- );
- assert.equal(
- tripleThreat([10, 9, 8, -100, -99, 99, 100]),
- false
- );
- console.log('Success!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement