Skip to content

Instantly share code, notes, and snippets.

@TerribleDev
Created February 5, 2022 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerribleDev/3b2f3f2124d95d1ab0d0d6b485ad8db4 to your computer and use it in GitHub Desktop.
Save TerribleDev/3b2f3f2124d95d1ab0d0d6b485ad8db4 to your computer and use it in GitHub Desktop.
Dedupe
function dedupeWithDictionary(numbers) {
return Object.keys(numbers.reduce((accum, current) => {
accum[current] = true
return accum
}, {}))
}
function dedupeWithSet(numbers) {
return new Set(numbers).values()
}
console.log(dedupeWithDictionary([1, 2, 1, 5, 5, 7]).map(Number))
console.log(dedupeWithSet([1, 2, 1, 5, 5, 7]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment