Given a (JS) array of integers, I am trying to ascertain if it is zer0-balanced -- that is, for any element x there is a corresponding element of -x - in a single line of code.
I would think you could do this using every()
and includes()
but can't quite get the right logic.
arr.every(n => arr.includes(-n))
obviously does not work because includes()
is not a function, but that's the idea I've been failing least with. where to take this next? thank you!