how can I take the samllest missing positive integer from array of integers in js (I didn’t fiund any answer for my question, all I found was in other languages)
example
[-2, 6, 4, 5, 7, -1, 1, 3, 6, -2, 9, 10, 2, 2]
>Solution :
good question
let nums = [-2, 6, 4, 5, 7, -1, 1, 3, 6, -2, 9, 10, 2, 2];
console.log(smallestMissing(nums));
function smallestMissing(nums) {
let n = 1;
while (nums.includes(n)) n++;
return n
}
EDIT:
Can you please try to tell me what’s wrong with my code without downvoting?