Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Last active March 27, 2016 11:33
Show Gist options
  • Save ArtemAvramenko/d578df6c9862ee93ab56 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/d578df6c9862ee93ab56 to your computer and use it in GitHub Desktop.
let findUniquePair = numbers =>
((xor, n1) => [n1, n1 ^ xor]) (
...((xor, xors) => [xor, xors.find(n => n && n != xor) || 0]) (
...numbers.reduce(
(r, n) => [ r[0] ^ n, r[1].map((val, i) => val ^ (n & (2 ** i) && n)) ],
[0, new Uint32Array(32)])));
let numbers = findUniquePair([10, 20, 9, 10, 3, 20]);
console.log(numbers); // [3, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment