Created
November 25, 2014 18:49
-
-
Save sobecreative/0804baddf0790f9a3c73 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 tripleUp.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 tripleUp(array) { | |
for (var i = 1; i < array.length; i++) { | |
if (array[i] = array[i+1] != 1) { | |
return false; | |
} | |
else { | |
return true; | |
} | |
} | |
} | |
/******************************** | |
* YOUR CODE ABOVE HERE | |
********************************/ | |
assert.equal( | |
tripleUp([1, 4, 5, 6, 2]), | |
true | |
); | |
assert.equal( | |
tripleUp([1, 2, 3]), | |
true | |
); | |
assert.equal( | |
tripleUp([1, 2, 4, 5, 7, 6, 5, 6, 7, 6]), | |
true | |
); | |
assert.equal( | |
tripleUp([1, 2, 4, 5, 7, 6, 5, 7, 7, 6]), | |
false | |
); | |
assert.equal( | |
tripleUp([1,2]), | |
false | |
); | |
assert.equal( | |
tripleUp([10, 9, 8, -100, -99, -98, 100]), | |
true | |
); | |
assert.equal( | |
tripleUp([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