Last active
December 25, 2015 16:49
-
-
Save bzupnick/7008237 to your computer and use it in GitHub Desktop.
easy to understand function to delete duplicated elements in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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