Created
April 5, 2020 15:50
-
-
Save primofin/802a91344dbe4142fe50cc52b25ee4b8 to your computer and use it in GitHub Desktop.
JavaScript: HackerRank Sock Merchant
This file contains hidden or 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
| /* 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