Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if numbers are consecutive javascript

 /**
 * Given an array of number, group algebraic sequences with d=1
 * [1,2,3,4,5,6] => true
 * [1,2,4,5,6] => false
 */
 var arr = [1,2,4,5,6];
 const differenceAry = arr.slice(1).map(function(n, i) { return n - arr[i]; })
 const isDifference= differenceAry.every(value => value == 1)
 console.log(isDifference);			// False
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #numbers #consecutive #javascript
ADD COMMENT
Topic
Name
3+9 =