Arrays - Find missing numbers in a Sequence

后端 未结 15 1349
小鲜肉
小鲜肉 2021-02-01 04:08

I\'m trying to find an easy way to loop (iterate) over an array to find all the missing numbers in a sequence, the array will look a bit like the one below.

var nu

15条回答
  •  时光说笑
    2021-02-01 05:01

    Watch your leading zeroes, they will be dropped when the array is interpreted-

    var A= [0189459, 0189460, 0189461, 0189463, 0189465]

    (A returns [189459,189460,189461,189463,189465])

    function absent(arr){
        var mia= [], min= Math.min.apply('',arr), max= Math.max.apply('',arr);
        while(min

    var A= [0189459, 0189460, 0189461, 0189463, 0189465]; alert(absent(A))

    /* returned value: (Array) 189462,189464 */

提交回复
热议问题