晚上迅雷前端笔试第二道编程题如何排序啊?
晚上迅雷前端笔试第二道编程题如何排序啊??一直没啥思路,求教:
#迅雷##前端工程师#String.prototype.getSuffixList = function(suffix) {//TODO:编写代码逻辑 ,不使用正则//输出结果var str = this.split(" ");var obj = {};for (var i = 0; i < str.length; i++) {if (str[i].indexOf(suffix) != -1) {if (obj[str[i]] == undefined) {obj[str[i]] = 1;} else {obj[str[i]]++;}}}console.log(obj); //输出: { beautiful: 3, wonderful: 2, helpful: 1, grateful: 2 }//怎样根据属性值进行排序啊var result = '';for (var k in obj) {if (obj.hasOwnProperty(k)) {result += k + "=" + obj[k] + ",";}}}