标签:
Take away:
var data = ["vote1", "vote2", "vote1", "vote2"]; var reducer = function(acc, value){ if(acc[value]){ acc[value] = acc[value] + 1; }else{ acc[value] = 1; } return acc; }; var res = data.reduce(reducer ,{}); console.log(res);
[Javascript] Advanced Reduce: Common Mistakes
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5008972.html