js 分组&字符串拼接

2021-02-08 16:15

阅读:647

标签:join   字符串拼接   nts   group   div   nbsp   lte   ++   ace   

 /**
         * 分组
         * @@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||‘‘);
            }
        }

 

js 分组&字符串拼接

标签:join   字符串拼接   nts   group   div   nbsp   lte   ++   ace   

原文地址:https://www.cnblogs.com/zhuwansu/p/13073040.html


评论


亲,登录后才可以留言!