Skip to content

Instantly share code, notes, and snippets.

@minmaxdata
Created August 13, 2018 16:59
Show Gist options
  • Select an option

  • Save minmaxdata/de79b6bcb0425af116cdf4f122e9a622 to your computer and use it in GitHub Desktop.

Select an option

Save minmaxdata/de79b6bcb0425af116cdf4f122e9a622 to your computer and use it in GitHub Desktop.
Count Duplicates in an array
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