【发布时间】:2021-09-19 11:40:04
【问题描述】:
我的脚本不能只打印数据中的最后一个标记, 我的脚本应该打印 zil,因为它是我数据中最大的变化
var olddata =
[
{"token": "NORD", "oldprice": 1},
{"token": "DYP", "oldprice": 2.43},
{"token": "ZIL", "oldprice": 0.20},
{"token": "VET", "oldprice": 6.33}
]
var newdata =
[
{"token": "NORD", "newprice": 1.20},
{"token": "DYP", "newprice": 2.80},
{"token": "ZIL", "newprice": 0.40},
{"token": "VET", "newprice": 6.90}
]
function findBiggestChange(oldData, newData) {
var previousDifference = null;
var changeIndex;
oldData.forEach((obj, i) => {
var data = newData.find(d => d.token === obj.token);
var currentDifference = previousDifference ? Math.abs.forEach(data.newprice - obj.oldprice) : data.newprice;
changeIndex = currentDifference > previousDifference ? i : 0;
});
}
findBiggestChange(olddata,newdata);
【问题讨论】:
标签: javascript node.js arrays math foreach