Skip to content

Instantly share code, notes, and snippets.

@MadeByMike
Created June 4, 2014 01:29
Show Gist options
  • Save MadeByMike/09ac4b81dc9b8e08db33 to your computer and use it in GitHub Desktop.
Save MadeByMike/09ac4b81dc9b8e08db33 to your computer and use it in GitHub Desktop.
// This method is kind of cheeky in its implementation.
// It uses the JavaScript’s object to add every item in the array as key.
// As we all know, objects accepts only unique keys and sure we did capitalize on that.
Array.prototype.unique = function() {
var o = {}, i, l = this.length, r = [];
for(i=0; i<l;i+=1) o[this[i]] = this[i];
for(i in o) r.push(o[i]);
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment