Skip to content

Instantly share code, notes, and snippets.

@vipulbhj
Last active March 26, 2019 11:52
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 vipulbhj/479c25da5421e398e9dbaf73090936e6 to your computer and use it in GitHub Desktop.
Save vipulbhj/479c25da5421e398e9dbaf73090936e6 to your computer and use it in GitHub Desktop.
let arr = [
{
firstName: 'Jon',
lastName: 'Doe'
},
{
firstName: 'example',
lastName: 'example'
},
{
firstName: 'Jon',
lastName: 'Doe'
}
];
const removeDuplicates = (arr) => {
const SymbolArray = [];
arr.forEach((item, index) => {
const {firstName, lastName} = item;
let keyStr = `${firstName}_${lastName}`;
SymbolArray.push(Symbol.for(keyStr));
});
const results = [];
SymbolArray.forEach((item, index) => {
if(SymbolArray.indexOf(item) === index) {
results.push(arr[index]);
}
});
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment