In the following code sample I understand that this bit of code does not find the unique value in the given array, but I am not wondering how to solve the toy problem, but wondering why the output contains the value 5 twice. [1, 2, 3, 4, 5, 5]
let arr = [1,2,3,4,5,5,3,2,1];
function findUniq(arr) {
let other = [];
let reduced = arr.reduce(function(allNums, num){
if(num in allNums) {
other.push(num);
} else {
allNums.push(num);
}
return allNums;
}, []);
return reduced;
}
console.log(findUniq(arr));
It seems to me that when arr[5] gets evaluated it should use the first part of the 'if statement' and push it into the 'other' array. (But maybe I'm not understanding the 'in' operator correctly)