Skip to content

Instantly share code, notes, and snippets.

@zhasm
Created December 21, 2010 01:53
Show Gist options
  • Save zhasm/749359 to your computer and use it in GitHub Desktop.
Save zhasm/749359 to your computer and use it in GitHub Desktop.
add unique function to Array
//add unique function to Array
Array.prototype.unique = function() {
var o = {}, i, l = this.length, r = [];
for(i=0; i<l;i++) o[this[i]] = this[i];
for(i in o) r.push(o[i]);
return r;
};
//usage:
// a = "a a bb";
// a =a.split(" ");
// a =a.unique();
// a =a.join(" ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment