Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript consecutive numbers in array

 /**
 * 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: #javascript #consecutive #numbers #array
ADD COMMENT
Topic
Name
6+6 =