Created
February 5, 2022 21:30
-
-
Save TerribleDev/3b2f3f2124d95d1ab0d0d6b485ad8db4 to your computer and use it in GitHub Desktop.
Dedupe
This file contains 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 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