The Now Platform® Washington DC release is live. Watch now!
Not long ago I came across a piece of code whose purpose was to eliminate the duplicates from a comma-separated list of email addresses. The approach taken was to put the email addresses in an array, sort the array, and then walk through the array eliminating adjacent entries that were the same. The function in question looked like this (with some test code):
var test = 'b@b.com,a@b.com,c@b.com,b@b.com,d@c.com';
test = dedupe(test);
gs.log('Test: ' + test);
function dedupe(emails) {
var email_list = emails.split(',');
email_list.sort();
var last = '';
for (var i = 0; i < email_list.length; i++) {
if (last == email_list) {
email_list.splice(i, 1);
i--;
} else {
last = email_list;
}
}
return email_list.join(',');
}
var test = 'b@b.com,a@b.com,c@b.com,b@b.com,d@c.com';
test = dedupe(test);
gs.log('Test: ' + test);
function dedupe(emails) {
var email_list = emails.split(',');
var set = {};
for (var i = 0; i < email_list.length; i++)
set[email_list] = true;
email_list = [];
for (var email in set)
email_list.push(email);
return email_list.join(',');
}
var set = {};
for (var i = 0; i < email_list.length; i++)
set[email_list] = true;
email_list = [];
for (var email in set)
email_list.push(email);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.