Arrays - Find missing numbers in a Sequence

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

    function missingNum(nums){
        const numberArray = nums.sort((num1, num2)=>{
          return num1 - num2;
       });
       for (let i=0; i < numberArray.length; i++){
          if(i !== numberArray[i]){
            return i;
          }
       }
     }
     console.log(missingNum([0,3,5,8,4,6,1,9,7]))
    

提交回复
热议问题