reduce2
var data = ["vote1", "vote2", "vote1", "vote2"];
function reducer(accumulator, value) {
if (accumulator[value]) {
accumulator[value] = accumulator[value] + 1;
} else {
accumulator[value] = 1;
}
return accumulator; ///ALWAYS remember to return the accumulator.
}
var tally = data.reduce(reducer, []); ///Always pass in an initial value for an accumulator.This Gist was automatically created by Carbide, a free online programming environment.