Last active
January 19, 2016 14:47
-
-
Save Kiwka/b38ec745f6b4783b48d6 to your computer and use it in GitHub Desktop.
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
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