Skip to content

Instantly share code, notes, and snippets.

@carlosdlf
Created October 31, 2015 14:11
Show Gist options
  • Save carlosdlf/e3b1d588e1e86a7429e2 to your computer and use it in GitHub Desktop.
Save carlosdlf/e3b1d588e1e86a7429e2 to your computer and use it in GitHub Desktop.
//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