Arrays - Find missing numbers in a Sequence

后端 未结 15 1447
小鲜肉
小鲜肉 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:52

    This can now be done easily as a one-liner with the find method:

    const arr = [1,2,3,5,6,7,8,9];
    
    return arr.find((x,i) => arr[i+1]-x > 1) + 1
    
    //4
    

提交回复
热议问题