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"];app

 

console.log(getWordCnt());blog

 

相關文章
相關標籤/搜索