Find missing element in an array of unique elements from 0 to n
I don't think there is a better than \$O(n)\$ and \$O(1)\$ to this problem. 

However you can simplify the code a little (trivial) by subtracting from the expected total.

const findVal = nums =&gt; vals.reduce((t, v) =&gt; t - v, nums.length * (nums.length + 1) / 2);


Or

function findVal(nums) {
    var total = nums.length * (nums.length + 1) / 2;
    for (const v of nums) { total -= v }
    return total;
}


BTW

The extra brackets are not needed when calculate the total

(x * (x + 1)) / 2 === x * (x + 1) / 2