Last active
September 5, 2017 18:21
-
-
Save kontrollanten/f538450ebf6cf98081b8a5a50ff3970e to your computer and use it in GitHub Desktop.
Get duplicates
This file contains hidden or 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 _contacts = [ | |
{ Name: 'Andy', Emails: ['[email protected]', '[email protected]'] }, | |
{ Name: 'Jason', Emails: ['[email protected]', '[email protected]'] }, | |
{ Name: 'Bart', Emails: ['[email protected]'] }, | |
{ Name: 'Richard', Emails: ['[email protected]'] } | |
]; | |
const byEmail = {}; | |
_contacts.forEach(con => { | |
con.Emails.forEach(email => { | |
byEmail[email] = byEmail[email] || []; | |
byEmail[email].push(con); | |
}); | |
}); | |
const dups = Object.keys(byEmail) | |
.filter(email => byEmail[email].length > 1) | |
.reduce((output, email) => { | |
output[email] = byEmail[email]; | |
return output; | |
}, {}); | |
console.log(dups); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment