repl.it
@Joan_IndianaInd/

missing numbers in array

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let nums = [1,2,4]

var findDisappearedNumbers = function(nums) {
    let missing = [];
    let seen = new Array(nums.length).fill(false);

    for (let i = 0; i < nums.length; i++) {
        seen[nums[i]-1] = true;
    };

    for (let i = 0; i < seen.length; i++) {
        if (!seen[i]){
          missing.push(i+1);
        }
    };

    return missing;
};

findDisappearedNumbers(nums)