set14

Detect duplicate emails in a signup list

14 / 26
read the snippet · pick its Big-O
function hasDuplicateEmail(users) {
const sorted = [users].sort(
(a, b) => a.email.localeCompare(b.email)
);
for (let i = 1; i < sorted.length; i++) {
if (sorted[i].email === sorted[i - 1].email) return true;
}
return false;
}