Created
July 28, 2013 13:44
-
-
Save psdtohtml5/6098630 to your computer and use it in GitHub Desktop.
JavaScript : Count unique items in an array
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
$.extend({ | |
countUnique : function(array) { | |
var result = []; | |
$.each(array, function(i,v) { | |
if($.inArray(v, result) == -1) { | |
result.push(v); | |
} | |
}); | |
return result.length; | |
} | |
}); | |
var array = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]; | |
$.countUnique(array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment