Skip to content

Instantly share code, notes, and snippets.

@primofin
Created April 5, 2020 15:50
Show Gist options
  • Select an option

  • Save primofin/802a91344dbe4142fe50cc52b25ee4b8 to your computer and use it in GitHub Desktop.

Select an option

Save primofin/802a91344dbe4142fe50cc52b25ee4b8 to your computer and use it in GitHub Desktop.
JavaScript: HackerRank Sock Merchant
/* https://www.hackerrank.com/challenges/sock-merchant */
let pairs = 0
const unpaired = new Set()
for (const color of arr)
if (unpaired.has(color)) {
pairs++
unpaired.delete(color)
} else unpaired.add(color)
return pairs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment