【发布时间】:2015-03-20 13:15:12
【问题描述】:
所以我有这个代码
Array.prototype.byCount= function(){
var itm, a= [], L= this.length, o= {};
for(var i= 0; i<L; i++){
itm= this[i];
if(!itm) continue;
if(o[itm]== undefined) o[itm]= 1;
else ++o[itm];
}
for(var p in o) a[a.length]= p;
return a.sort(function(a, b){
return o[b]-o[a];
});
}
这几乎是我所需要的,只是它不返回值的出现次数。
我试图重写它,但我总是在排序部分失败。
感谢您的帮助
【问题讨论】:
-
请向我们展示您重写它的尝试,然后我们将能够在排序部分为您提供帮助。
标签: javascript sorting frequency