Skip to content

Instantly share code, notes, and snippets.

@UncleBill
Created October 18, 2014 05:42
Show Gist options
  • Save UncleBill/25d7b4d962a402e0ac4e to your computer and use it in GitHub Desktop.
Save UncleBill/25d7b4d962a402e0ac4e to your computer and use it in GitHub Desktop.
uniqueAndCount
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