Created
August 13, 2018 16:59
-
-
Save minmaxdata/de79b6bcb0425af116cdf4f122e9a622 to your computer and use it in GitHub Desktop.
Count Duplicates in an array
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
| function hasDuplicates(numbers) { | |
| let memo = {}; | |
| let count = 0; | |
| numbers.map(number => { | |
| if (!memo[number]) { | |
| memo[number] = 1; | |
| } else { | |
| count++; | |
| } | |
| return count; | |
| }); | |
| return count; | |
| } | |
| hasDuplicates([1, 2, 2, 3, 3, 4, 6, 8, 6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment