Skip to content

Instantly share code, notes, and snippets.

@korczis
Created November 22, 2013 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korczis/7598657 to your computer and use it in GitHub Desktop.
Save korczis/7598657 to your computer and use it in GitHub Desktop.
JavaScript implementation of function for removing duplicate items from array
function removeDuplicates(vals) {
var res = [];
var tmp = vals.sort();
for (var i = 0; i < tmp.length; i++) {
res.push(tmp[i]);
while (JSON.stringify(tmp[i]) == JSON.stringify(tmp[i + 1])) {
i++;
}
}
return res;
}
console.log(removeDuplicates([1,2,3,4,5,4,3,3,2,1,]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment