Last updated 4 years ago
Was this helpful?
find unique number though Set() and assign value to 'a' and 'b'
Set()
if inputs first indexOf 'a' and inputs lastIndexOf 'a' is same 'a' is unique, return 'a' otherwise return 'b'
const stray = (numbers) => { const [a, b] = [...new Set(numbers)]; return numbers.indexOf(a) === numbers.lastIndexOf(a) ? a : b; };