public
Created

JavaScript implementation of function for removing duplicate items from array

  • Download Gist
removeDuplicates.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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,]));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.