es6元素出现的次数

////请输入下列水果共出现的次数
var arr = ["apple","orange","apple","orange","pear","orange"];
function getCount(){
arr.reduce(function(){},{})

}
function getWordCnt(){
return arr.reduce(function(prev,next){
prev[next] = (prev[next] + 1) || 1;
return prev;
},{});
}
var arr = ["apple","orange","apple","orange","pear","orange"];

 

console.log(getWordCnt());

 

posted @ 2018-03-08 16:18  ~丸子  阅读(1024)  评论(0编辑  收藏  举报