Skip to content

Instantly share code, notes, and snippets.

@McQuinTrix
Created June 17, 2015 17:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McQuinTrix/947fb46141bef3915763 to your computer and use it in GitHub Desktop.
Save McQuinTrix/947fb46141bef3915763 to your computer and use it in GitHub Desktop.
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