Skip to content

Instantly share code, notes, and snippets.

@CodeDotJS
Last active February 7, 2019 10:12
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 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(["fg.r.u.uzj+o.pw@kziczvh.com","r.cyo.g+d.h+b.ja@tgsg.z.com","fg.r.u.uzj+o.f.d@kziczvh.com","r.cyo.g+ng.r.iq@tgsg.z.com","fg.r.u.uzj+lp.k@kziczvh.com","r.cyo.g+n.h.e+n.g@tgsg.z.com","fg.r.u.uzj+k+p.j@kziczvh.com","fg.r.u.uzj+w.y+b@kziczvh.com","r.cyo.g+x+d.c+f.t@tgsg.z.com","r.cyo.g+x+t.y.l.i@tgsg.z.com","r.cyo.g+brxxi@tgsg.z.com","r.cyo.g+z+dr.k.u@tgsg.z.com","r.cyo.g+d+l.c.n+g@tgsg.z.com","fg.r.u.uzj+vq.o@kziczvh.com","fg.r.u.uzj+uzq@kziczvh.com","fg.r.u.uzj+mvz@kziczvh.com","fg.r.u.uzj+taj@kziczvh.com","fg.r.u.uzj+fek@kziczvh.com", "test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment