Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 = 2; i < array.length; ++i) {
if (array[i] == array[i-1] + 1 && array[i] == array[i-2] + 2) {
return true;
}
}
return false;
}
/********************************
* 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