Skip to content

Instantly share code, notes, and snippets.

@CodeDotJS
Last active February 7, 2019 10:12
Show Gist options
  • Save CodeDotJS/ea9eac63b5ae9a36fd77827e6c46f3ee to your computer and use it in GitHub Desktop.
Save CodeDotJS/ea9eac63b5ae9a36fd77827e6c46f3ee to your computer and use it in GitHub Desktop.
Unique Email Address - LeetCode Solution.
'use strict';
const numUniqueEmails = emails => {
const listofMails = [];
const storeUniqueEmails = [];
const mailLength = emails.length;
for (let i = 0; i <= mailLength - 1; i++) {
const filteredName = emails[i].split('+')[0].replace(/\./g, '') + '@' + emails[i].split('@')[1];
listofMails.push(filteredName);
}
const len = listofMails.length;
for (let j = 0; j < len; j++) {
if (storeUniqueEmails.indexOf(listofMails[j]) === -1) {
storeUniqueEmails.push(listofMails[j]);
}
}
return storeUniqueEmails.length;
};
console.log(numUniqueEmails(["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]", "[email protected]","[email protected]","[email protected]"]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment