Created
October 22, 2022 19:29
-
-
Save oguzhancvdr/b613c30918cd18f19e9d4f34914eba0e to your computer and use it in GitHub Desktop.
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
// for big array it is more performant | |
const removeDuplicates = (array) => { | |
const uniqueValues = []; | |
const seenMap = {}; | |
for (const item of array) { | |
if (seenMap[item]) continue; | |
seenMap[item] = true; | |
uniqueValues.push(item); | |
} | |
return uniqueValues; | |
}; | |
const rmDuplicates = (array) => { | |
// Turn our array into a Set, which can only contain | |
// unique values, and then make an array from that set. | |
return [...new Set(array)]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment