Arrays - Find missing numbers in a Sequence

后端 未结 15 1451
小鲜肉
小鲜肉 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 04:51

    ES6-Style

    var arr = [0189459, 0189460, 0189461, 0189463, 0189465]; 
    var [min,max] = [Math.min(...arr), Math.max(...arr)];
    var out = Array.from(Array(max-min),(v,i)=>i+min).filter(i=>!arr.includes(i));
    

    Result: [189462, 189464]

提交回复
热议问题