我编写了一个名为的函数frequency()
,它接受一个数组,计算在其中找到字符串的次数,然后根据这些结果返回一个对象。
代码:
var array = ["Diesel","Asos","Diesel","Paul Smith"];
function frequency(array) {
var frequency = {}, value;
for(var i = 0; i < array.length; i++) {
value = array[i];
if(value in frequency)
frequency[value]++;
else
frequency[value] = 1;
}
return frequency;
}
ordered = frequency(array);
样本输出:
{"Asos":1,"Diesel":2,"Paul Smith":1}
我现在如何根据计数的频率值对这个输出的对象进行排序?