- I have an array of sorted numbers being passed into my function
- I want to return the number of
numbersI'm missing
Example:
the array I pass is [1,5,6,9]
the numbers I'm missing are 2,3,4,7,8
the counter should be 5
what I'm attempting to do:
without using any built ins. while my next number in my list is not the next number already in my list I would increment by one.
function missing(numbers){
counter = 0;
let j = 1;
for(let i = 0; i<numbers.length; i++){
while(numbers[i+1] != numbers[i]+j){
j+=1;
counter+=1;
console.log("missing "+ numbers[i]+j)
}
}
return counter;
}