Skip to content

Instantly share code, notes, and snippets.

@kontrollanten
Last active September 5, 2017 18:21
Show Gist options
  • Save kontrollanten/f538450ebf6cf98081b8a5a50ff3970e to your computer and use it in GitHub Desktop.
Save kontrollanten/f538450ebf6cf98081b8a5a50ff3970e to your computer and use it in GitHub Desktop.
Get duplicates
const _contacts = [
{ Name: 'Andy', Emails: ['andy@protonmail.com', 'company@protonmail.com'] },
{ Name: 'Jason', Emails: ['jason@protonmail.com', 'company@protonmail.com'] },
{ Name: 'Bart', Emails: ['bart@protonmail.com'] },
{ Name: 'Richard', Emails: ['richard@protonmail.com'] }
];
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