Created
November 5, 2014 11:23
-
-
Save VincentHelwig/b1a555e7c7c4c4393978 to your computer and use it in GitHub Desktop.
Get unique array
This file contains hidden or 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
// FROM http://jsperf.com/compare-array-unique-versions/4 | |
Array.prototype.getUnique = function () { | |
var arr = this; | |
var newArr = [], | |
i = 0, | |
j = 0, | |
obj = {}, | |
len = arr.length; | |
while (len--) { | |
if (!obj[arr[i]]) { | |
obj[arr[i]] = 1; | |
newArr[j] = arr[i]; | |
j++; | |
} | |
i++; | |
} | |
return newArr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment