Open 02020 opened 3 years ago
const ____kit = {
reduce: (arr, initial = {}) => (f) => arr.reduce(f, initial),
keys: (keys, initial = {}) => (f) => Object.keys(keys).reduce(f, initial),
mergeArray: (source, target) =>
source.map((x, index) => {
return Object.assign({}, x, target[index]);
}),
};
const RR = {
reduceO: (array, f) => array.reduce(f, {}),
// 先分组在转换
groupBy: (array, f) => RR.keysMap(array.reduce(f, {})),
};
const keys = ['a', 'b', 'c', 'd'];
const keyArray = [
['1', '2', '3', '4'],
['11', '22', '33', '44'],
];
const faa = (item, index) => {
const o = kit.fR((item, i) => [keys[i], item])(item);
return [index, o];
};
console.log(kit.fR(faa, [])(keyArray));
// 消息通知
const image = 'https://img-cdn-qiniu.dcloud.net.cn/new-page/uni.png';
const list = [
[image, '缴费提醒', '您本月应缴费信息提醒', '8:35', 2],
[image, '欠费补缴通知', '你到期未缴费欠费补缴通知', '昨天', 2],
[image, '催缴涵', '欠费未补缴发送催缴涵', '昨天', 2],
[image, '在线签约提醒', '电子合同在线签约提醒', '2020-09-08', 2],
[image, '合同到期涵', '履约合同到期发送到期涵', '2020-09-08', 2],
[image, '居住人信息补充通知', '租赁资产居住人信息录入通知', '2020-09-08', 2],
];
const keys = ['src', 'title', 'sub', 'topRight', 'num'];
kit.keysTo(keys)(list);
const toArray = (key, item, index, acc) => item;
temp = kit.toGroup('group')(temp);
kit.fR(toArray, [])(temp);
const data = { a: '11', b: '22',};
const initial = { a: 'a1', aa: 'aa1', bb: 'bb2',};
const execute = (acc, key, value) => acc[key] = value;
const f = (key, value, index, acc) => execute(acc, key, value);
kit.fR(f, initial)(data);
console.log(initial);