Skip to content

Instantly share code, notes, and snippets.

@sebnilsson
Last active October 11, 2015 11:28
Show Gist options
  • Save sebnilsson/3852314 to your computer and use it in GitHub Desktop.
Save sebnilsson/3852314 to your computer and use it in GitHub Desktop.
Sort and remove duplicates
var items = [ 'ABC', '123', 'BAA' ];
items.sort(function (a, b) {
var aVal = a.val.toLowerCase();
var bVal = b.val.toLowerCase();
return ((aVal < bVal) ? -1 : ((aVal > bVal) ? 1 : 0));
});
var last = items[0];
for (var i = 1; i < items.length; i++) {
var item = items[i];
if (item.value === last.value) {
// TODO: Remove item
}
last = item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment