Skip to content

Instantly share code, notes, and snippets.

@rkaw92
Created January 7, 2020 15:08
Show Gist options
  • Save rkaw92/07bfffd9f4a4ed149782fce0bb1706a5 to your computer and use it in GitHub Desktop.
Save rkaw92/07bfffd9f4a4ed149782fce0bb1706a5 to your computer and use it in GitHub Desktop.
'use strict';
function findPairs(inputs) {
const unpairedNumbers = new Set();
const pairs = [];
for (let element of inputs) {
if (unpairedNumbers.has(element)) {
pairs.push(element);
unpairedNumbers.delete(element);
} else {
unpairedNumbers.add(element);
}
}
return pairs;
}
console.log(findPairs([ 1, 2, 3, 5, 5, 5, 5, 5, 1, 8 ]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment