day181-Reduce求对象中多个属性的和

要点

求对象中多个属性的和

let data = [
{
tqaModifyCount: 9,
tqaMarkCount: 19
},
{
tqaModifyCount: 3,
tqaMarkCount: 3
}
]
let tgt = {
tqaModifyCounts: 12
tqaMarkCounts: 22
}

代码

function sum (dataArr) {
return dataArr.reduce((acc, obj) => {
return {
tqaModifyCounts: acc.tqaModifyCount + obj.tqaModifyCount,
tqaMarkCounts: acc.tqaMarkCount + obj.tqaMarkCount
}
})
}
文章作者: lmislm
文章链接: http://lmislm.com/2019/07/13/2019-07-13/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LMISLMのBlog