Last active
March 26, 2019 11:52
-
-
Save vipulbhj/479c25da5421e398e9dbaf73090936e6 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
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