Skip to content

Instantly share code, notes, and snippets.

@say2joe
Created January 26, 2015 19:06
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 say2joe/f7292eecd4bea9f06845 to your computer and use it in GitHub Desktop.
Save say2joe/f7292eecd4bea9f06845 to your computer and use it in GitHub Desktop.
JS Object Prototype Augmentation (JS helper methods)
if (![].unique) {
Array.prototype.unique = function() {
var n = {}, r = [], i = 0, l = this.length;
for (; i < l; i++) {
if (this[i] && !n[this[i]]) {
n[this[i]] = true;
r.push(this[i]);
}
}
return r;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment