Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JoseGonzalez321/8f4a2d77dd193b22028952eabae4d39e to your computer and use it in GitHub Desktop.
Save JoseGonzalez321/8f4a2d77dd193b22028952eabae4d39e to your computer and use it in GitHub Desktop.
// Find duplicates in an array of ints
// IMO, a bit messier/complicated than should be. But it works.
function findDupes(arr) {
var counted = arr.reduce((all, item) => {
all[item] = (all[item] || 0) + 1;
return all;
}, {});
return Object.keys(counted).filter(x => counted[x] > 1).map(x => parseInt(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment