/** * 分组 * @@param arr 源 * @@param k key genertor * @@param f group by */ function group(arr, k, f) { var res = []; for (var i = 0; i < arr.length; i++) { var item = arr[i] var resItem = res.filter(m => f(m.key, item))[0]; if (resItem) resItem.data.push(item) else k(item) && res.push({ key: k(item), data: [item] }); } return res; } function txtBuilder(sp) { this.sp=sp||"**" this.arr = []; this.add = function () { var txt = arguments[0]; for (var i = 1, len = arguments.length; i < len; i++) { txt = txt.replace(this.sp, arguments[i]) } this.arr.push(txt) return this; } this.join = function (jsp) { return this.arr.join(jsp||‘‘); } }