Skip to content

Instantly share code, notes, and snippets.

@bzupnick
Last active December 25, 2015 16:49
Show Gist options
  • Save bzupnick/7008237 to your computer and use it in GitHub Desktop.
Save bzupnick/7008237 to your computer and use it in GitHub Desktop.
easy to understand function to delete duplicated elements in an array
function deleteDuplicates(arr) {
arr.sort();
var lastElement = '';
var arrDuplicate = arr;
for (var i = arrDuplicate.length; i >= 0; i--) {
if (arrDuplicate[i] == lastElement) {
arr.splice(i, 1);
}
lastElement = arrDuplicate[i];
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment