Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript consecutive numbers in array

function makeArrayConsecutive2(statues) {
    var rang = statues.sort(function (a, b){
        return (a - b) 
    });
    var some=0;
 
    if(rang.length-1==0){
        return 0;
    }else{
    for(i=0;i<=rang.length-2;i++){
        some+=(rang[i+1]-rang[i]-1);
    }
    return some;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #consecutive #numbers #array
ADD COMMENT
Topic
Name
9+2 =