js 分组&字符串拼接
2021-02-08 16:15
标签:join 字符串拼接 nts group div nbsp lte ++ ace js 分组&字符串拼接 标签:join 字符串拼接 nts group div nbsp lte ++ ace 原文地址:https://www.cnblogs.com/zhuwansu/p/13073040.html /**
* 分组
* @@param arr 源
* @@param k key genertor
* @@param f group by
*/
function group(arr, k, f) {
var res = [];
for (var i = 0; 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 ) {
txt = txt.replace(this.sp, arguments[i])
}
this.arr.push(txt)
return this;
}
this.join = function (jsp) {
return this.arr.join(jsp||‘‘);
}
}