Created
October 18, 2014 05:42
-
-
Save UncleBill/25d7b4d962a402e0ac4e to your computer and use it in GitHub Desktop.
uniqueAndCount
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
function uniqueAndCount(list) { | |
var index = 0, | |
num = 0; | |
var result = []; | |
for (var i = 0; i < list.length; i++) { | |
if ($.inArray(list[i], result) < 0) { | |
result.push(list[i]); | |
while ($.inArray(list[i], list, index) > -1) { | |
num++; | |
index = $.inArray(list[i], list, index) + 1; | |
} | |
result.push(num); | |
num = 0; | |
index = 0; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment