Find All Numbers Disappeared in an Array The task
is taken from leetcode


  Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array),
  some elements appear twice and others appear once.
  
  Find all the elements of [1, n] inclusive that do not appear in this
  array.
  
  Could you do it without extra space and in O(n) runtime? You may
  assume the returned list does not count as extra space.
  
  Example:
  
  Input:
  
  [4,3,2,7,8,2,3,1]
  
  Output:
  
  [5,6]


My solution

/**
 * @param {number[]} nums
 * @return {number[]}
 */
var findDisappearedNumbers = function(nums) {
  return nums
    .reduce((arr, x) =&gt; {
      arr[x - 1] = null;
      return arr;
    }, Array.from({length: nums.length}, (v, k) =&gt; k+1))
    .filter(Boolean);
};


There has to be a more elegant solution to that.
You have created a good solution, just a few style points that can reduce code size.

Why null rather than false or even 0 in arr[x - 1] = null;

Why not use commas to remove need for return. Eg .reduce((arr, x) =&gt; {arr[x - 1] = null; return arr; } becomes .reduce((arr, x) =&gt; (arr[x - 1] = null, arr))

To create an array of indexes you could have used the shorter forms, Array.from(nums, (item, i) =&gt; i + 1)) or nums.map((item,i) =&gt; i + 1)


Rewrites
function findMissing(arr) {
  return arr
    .reduce((a, i) =&gt; (a[i - 1] = 0, a), arr.map((item, i) =&gt; i + 1))
    .filter(Boolean);
}

or
const findMissing = arr =&gt; arr
  .reduce((a, i) =&gt; (a[i - 1] = 0, a), arr.map((item, i) =&gt; i + 1))
  .filter(Boolean);

You could also have solved it with a set as follows
function findMissing(arr) {
    const s = new Set(arr), res = [];
    var i = arr.length;
    while (i) { s.has(i--) || res.push(i + 1) }
    return res;
}