Created
July 18, 2013 21:53
-
-
Save lukesh/6033451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!Array.prototype.unique) { | |
Object.defineProperty(Array.prototype, "unique", { | |
value: function(key) { | |
var o = {}, i, l = this.length, r = [] | |
for(i=0; i<l;i+=1) { | |
if(key) { | |
var _key = "" | |
,self = this | |
if(typeof key == "string") { | |
_key = key | |
} else if(typeof key == "function") { | |
_key = key(self[i]) | |
} else { | |
key.forEach(function(e) { | |
_key += self[i][e] | |
}) | |
} | |
o[_key] = this[i] | |
} else { | |
o[this[i]] = this[i] | |
} | |
} | |
for(i in o) { | |
r.push(o[i]) | |
} | |
return r | |
} | |
,writable: false | |
,enumerable: false | |
,configurable: false | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment