How to get the first missing smallest positive integer in an unsorted integer array with Node.js

1 Answer

0 votes
function findSmallestMissingNumber(arr) {
    const numSet = new Set(arr);

    let index = 1;
    while (true) {
        if (!numSet.has(index)) {
            return index;
        }
        index++;
    }
}

const arr = [7, 3, 2, 4, -1, 1];

console.log(findSmallestMissingNumber(arr));


/*
run:

5

*/

 



answered Jun 4 by avibootz
...