Created
November 1, 2022 00:45
-
-
Save vinicioslc/ecafcfb5b18050118c4aeeba81912c1a to your computer and use it in GitHub Desktop.
A good remove duplicates function in nodejs that uses good readability principles and performance concepts like hashmaps
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
const removeDuplicateStrings = (array) => { | |
const uniqueValues = []; | |
const seenMap = {}; | |
for (const item of array) { | |
if (seenMap[item]) continue; | |
seenMap[item] = true; | |
uniqueValues.push(item); | |
} | |
return uniqueValues; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment