当前位置:网站首页>Find objects with the same property value Cumulative number Summarize
Find objects with the same property value Cumulative number Summarize
2022-08-01 12:02:00 【Snow Xiaoxin】
Find objects with the same property value 累加数量 汇总
const oldArray = [
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 1,
},
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "2",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
];
const sumTabData = countTabFun(oldArray);
//汇总数据
export function countTabFun(arr) {
const data = arr.reduce((total, cur, index) => {
let hasValue = total.findIndex((current) => {
return (
current.batchNo == cur.batchNo &&
current.factoryCnName == cur.factoryCnName &&
current.goodsCnName == cur.goodsCnName
);
});
hasValue == -1 && total.push(cur);
hasValue != -1 &&
(total[hasValue].inputNum = total[hasValue].inputNum + cur.inputNum);
return total;
}, []);
return data;
}

边栏推荐
- [Nodejs] node的fs模块
- 重庆市大力实施智能建造,推动建筑业数字化转型,助力“建造强市”
- Online - GCeasy GC log analysis tools
- The difference between undefined and null in JS
- ACL 2022 | 文本生成的相关前沿进展
- Istio Meetup China: Full Stack Service Mesh - Aeraki Helps You Manage Any Layer 7 Traffic in an Istio Service Mesh
- MMF的初步介绍:一个规范化的视觉-语言多模态任务框架
- 表达式引擎在转转平台的实践
- Tencent Cloud Native: Service Mesh Practice of Areaki Mesh in the 2022 Winter Olympics Video Live Application
- R语言拟合ARIMA模型:使用forecast包中的auto.arima函数自动搜索最佳参数组合、模型阶数(p,d,q)、设置seasonal参数指定在模型中是否包含季节信息
猜你喜欢
随机推荐
字体反爬之好租
STM32 CAN filter configuration details
(ES6以上以及TS) Map对象转数组
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
用户体验 | 如何度量用户体验 ?
ECCV22|只能11%的参数就能优于Swin,微软提出快速预训练蒸馏方法TinyViT
pandas connects to the oracle database and pulls the data in the table into the dataframe, filters all the data from the current time (sysdate) to one hour ago (filters the range data of one hour)
判断JS数据类型的四种方法
《MySQL核心知识》第6章:查询语句
千万级乘客排队系统重构&压测方案——总结篇
【CLion】CLion 总是提示 “This file does not belong to any project target xxx” 的解决方法
leetcode每日一题:字符串压缩
如何设计一个分布式 ID 发号器?
安装apex报错
JS数据类型转换完全攻略
力扣解法汇总1374-生成每种字符都是奇数个的字符串
Meshlab&Open3D SOR滤波
JWT
sql中ddl和dml(数据库表与视图的区别)
leetcode/submatrix element sum









