Created
October 31, 2015 14:11
-
-
Save carlosdlf/e3b1d588e1e86a7429e2 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
//see CONSOLE! | |
var votes = [ | |
"angular", | |
"angular", | |
"react", | |
"react", | |
"react", | |
"angular", | |
"ember", | |
"react", | |
"vanilla" | |
]; | |
var initialValue = {}; | |
var reducer = function(tally, vote) { | |
if (!tally[vote]) { | |
tally[vote] = 1; | |
} else { | |
tally[vote] = tally[vote] + 1; | |
} | |
return tally; | |
}; | |
var result = votes.reduce(reducer, initialValue); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment