Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

JavaScript implementation of function for removing duplicate items from array

View removeDuplicates.js
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,]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.