Description:
There is an array with some numbers. All numbers are equal except for one. Try to find it!
findUniq([ 1, 1, 1, 2, 1, 1 ]) === 2
findUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55
It’s guaranteed that array contains at least 3 numbers.
The tests contain some very huge arrays, so think about performance.
function findUniq(arr) {
// do magic
let arrIdx = [...new Set([...arr])]
return arr.indexOf(arrIdx[0]) === arr.lastIndexOf(arrIdx[0]) ? arrIdx[0] : arrIdx[1]
}
오..내가 생각해도 좀 잘 짠듯