js 分组&字符串拼接

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

 

js 分组&字符串拼接

上一篇:jQuery Organization Chart


下一篇:PHP代码审计学习(2)——php.ini核心配置