merge contract

This commit is contained in:
chenjianan
2019-05-27 15:56:05 +08:00
parent 8854c04660
commit 9ff37964b5
2 changed files with 86 additions and 20 deletions

View File

@@ -105,3 +105,31 @@ export function sleep(time) {
setTimeout(resolve, time)
})
}
export function groupBy(datas, keys, callBack) {
const list = datas || []
const groups = []
const result = []
list.forEach(v => {
const key = {}
keys.forEach(k => {
key[k] = v[k]
})
let group = groups.find(v => {
return v._key === JSON.stringify(key)
})
if (!group) {
group = {
_key: JSON.stringify(key),
key: key
}
groups.push(group)
}
group.key.数量 = callBack(group.data, v)
group.data = callBack(group.data, v)
})
groups.map(v => {
result.push(v.key)
})
return result
}