Created
June 17, 2015 17:39
-
-
Save McQuinTrix/947fb46141bef3915763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert'); | |
/******************************** | |
* Return true if the array contains, somewhere, three increasing | |
* adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25. | |
* | |
* See the asserts below for examples of input | |
* 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 len = array.length; | |
for(var i=0; i<len-2; i++){ | |
if(array[i+1]==array[i]+1){ | |
if(array[i+2]== array[i]+2){ | |
return true | |
} | |
} | |
} | |
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!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment