Created
February 22, 2013 14:07
-
-
Save drifterz28/5013637 to your computer and use it in GitHub Desktop.
Javascript unique function from http://jspro.com/raw-javascript/five-php-functions-id-love-to-see-in-javascript/
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
Array.prototype.unique = function (sort, sortingFunction) { | |
var array = []; | |
for (var i = 0; i < this.length; i++) { | |
if (array.inArray(this[i]) === false) | |
array.push(this[i]); | |
} | |
if (sort === true) { | |
if (typeof sortingFunction === 'function') | |
array.sort(sortingFunction); | |
else | |
array.sort(); | |
} | |
return array; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment