迅雷前端
写的不太好,不过还是都AC了
第一题修改Bind函数
var self = null Function.prototype.bind = function() { if (self == null){ self = this } var context = [].shift.call(arguments), args = [].slice.call(arguments); return function() { return self.apply(context, [].concat.call(args, [].slice.call(arguments))); } };
评论区 @ququququc 第一题的解决方案,这个更好
Function.prototype.bind = function () { var self = this.self || this, context = [].shift.call(arguments), args = [].slice.call(arguments), res = function () { return self.apply(context, [].concat.call(args, [].slice.call(arguments))); } res.self = this return res };
第二题后缀
String.prototype.getSuffixList = function (suffix) { var result = "", strs = this.split(" "), LEN = strs.length, map = {}, res; for (var i = LEN - 1; i >= 0; i--) { res = strs[i].indexOf(suffix); if (res != -1) { if (strs[i] in map) { map[strs[i]]++ } else { map[strs[i]] = 1 } } } var keys = Object.keys(map).sort(function (a, b) { return map[b] - map[a] }); for (var j = 0; j < keys.length; j++) { result += keys[j] + "=" + map[keys[j]] + "," } return result.substring(0, result.length - 1);//字符串 };#迅雷##前端工程师#