Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. * and expected output.
  2. *
  3. * If you have node installed, all you need to do to test
  4. * your code is run: `node tripleThreat.js`. If you see errors,
  5. * it is because the tests below did not pass. Once the
  6. * tests do pass, you will see a log of `Success!`
  7. *
  8. * YOUR CODE BELOW HERE
  9. ********************************/
  10.  
  11.  
  12. function tripleThreat(array) {
  13. var isTrip;
  14. var numChain = 1;
  15. var currVal;
  16. var nextExpected;
  17. var nextVal;
  18. for (i = 0; i < array.length - 1; i++){
  19. currVal = array[i];
  20. nextVal = array[i + 1];
  21. nextExpected = currVal + 1;
  22. if(nextVal === nextExpected){
  23. numChain++;
  24.  
  25. if(numChain === 3){
  26. isTrip = true;
  27. return isTrip;
  28. }
  29. }else{
  30. numChain = 1;
  31. }
  32. //currVal = array[i];
  33. //currVal = array[i];
  34.  
  35.  
  36. }
  37. return false;
  38. }
  39.  
  40. /********************************
  41. * YOUR CODE ABOVE HERE
  42. ********************************/
  43.  
  44. assert.equal(
  45. tripleThreat([1, 4, 5, 6, 2]),
  46. true
  47. );
  48.  
  49. assert.equal(
  50. tripleThreat([1, 2, 3]),
  51. true
  52. );
  53.  
  54. assert.equal(
  55. tripleThreat([1, 2, 4, 5, 7, 6, 5, 6, 7, 6]),
  56. true
  57. );
  58.  
  59. assert.equal(
  60. tripleThreat([1, 2, 4, 5, 7, 6, 5, 7, 7, 6]),
  61. false
  62. );
  63.  
  64. assert.equal(
  65. tripleThreat([1,2]),
  66. false
  67. );
  68.  
  69. assert.equal(
  70. tripleThreat([10, 9, 8, -100, -99, -98, 100]),
  71. true
  72. );
  73.  
  74. assert.equal(
  75. tripleThreat([10, 9, 8, -100, -99, 99, 100]),
  76. false
  77. );
  78.  
  79. console.log('Success!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement