Skip to content

Instantly share code, notes, and snippets.

@Kiwka
Created January 19, 2016 15:36
Show Gist options
  • Save Kiwka/f17140d684ab6554b538 to your computer and use it in GitHub Desktop.
Save Kiwka/f17140d684ab6554b538 to your computer and use it in GitHub Desktop.
var t = {'nike': 5};
var brands = [t, 'New Balance', 'Adidas', 'asics', t, 'New Balance', t, 'Nike', t, 'asics'];
var newMap = [];
var quantities = [];
var max = 0;
var maxItem;
brands.forEach(function(item, index, array){
if(newMap.indexOf(item) < 0) {
newMap.push(item);
quantities[newMap.length - 1] = 1;
} else {
var q = ++quantities[newMap.indexOf(item)];
if (q > max) {
max = q;
maxItem = item;
}
}
});
console.log(maxItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment