Created
January 19, 2016 15:36
-
-
Save Kiwka/f17140d684ab6554b538 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 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