Created
January 7, 2020 15:08
-
-
Save rkaw92/07bfffd9f4a4ed149782fce0bb1706a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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