Skip to content

Instantly share code, notes, and snippets.

@oguzhancvdr
Created October 22, 2022 19:29
Show Gist options
  • Save oguzhancvdr/b613c30918cd18f19e9d4f34914eba0e to your computer and use it in GitHub Desktop.
Save oguzhancvdr/b613c30918cd18f19e9d4f34914eba0e to your computer and use it in GitHub Desktop.
// 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