Skip to content

Instantly share code, notes, and snippets.

@Kiwka
Last active January 19, 2016 14:47
Show Gist options
  • Save Kiwka/b38ec745f6b4783b48d6 to your computer and use it in GitHub Desktop.
Save Kiwka/b38ec745f6b4783b48d6 to your computer and use it in GitHub Desktop.
var brands = ['Nike', 'New Balance', 'Adidas', 'asics', 'Adidas', 'New Balance', 'New Balance', 'Nike', 'Adidas', 'asics'];
var newMap = {};
var max = 1;
var maxItem = brands[0];
brands.forEach(function(item, index, array){
if(!newMap[item]) {
newMap[item] = 1;
} else {
newMap[item]++;
if (newMap[item] > max) {
max = newMap[item];
maxItem = item;
}
}
});
console.log(maxItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment