function lonelyinteger(a) {
// destructure the first (and only) element, sort then reduce
const [lonely] = a.sort((a, b) => a - b).reduce((acc, curr) => {
// here we'll start the reduce with an empty array and check
// if the current integer is already on the array
if(!acc.includes(curr)) {
// if not, we'll add it
acc.push(curr)
} else {
// if so, we'll remove the last element.
// This way we'll be removing all duplicates
acc.pop()
}
// return the array to the next iteration
return acc
}, [])
return lonely
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (5)
simplify it by using xor
Way more simpler indeed, thanks for the tip Frank!
A very simple process indeed. Well done
`
You can check this out too if you are looking for an explicit process that is self-explanatory too.