gpt4 book ai didi

javascript - 如何删除此代码中 ES6 箭头函数的使用

转载 作者:行者123 更新时间:2023-11-28 17:45:03 25 4
gpt4 key购买 nike

我不熟悉 ES6 箭头函数,我从 vendor 那里收到了以下代码:

Highcharts.seriesType('linearregression', 'pareto', {
name: 'Linear Regression'
}, {
setDerivedData: function() {
if (this.baseSeries.yData.length > 1) {
var xValues = this.baseSeries.xData,
yData = this.baseSeries.yData,
mainData = this.baseSeries.data;
var sum = [0, 0, 0, 0, 0],
len = xValues.length,
data, rise, gradient, intercept;
Highcharts.each(xValues, function(x, i) {
sum[0] += x;
sum[1] += yData[i];
sum[2] += x * x;
sum[3] += x * yData[i];
sum[4] += yData[i] * yData[i];
});
run = ((len * sum[2]) - (sum[0] * sum[0]));
rise = ((len * sum[3]) - (sum[0] * sum[1]));
gradient = run === 0 ? 0 : (rise / run);
intercept = (sum[1] / len) - ((gradient * sum[0]) / len);
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
};
function predict(x) {
return [mainData[x].name, round((gradient * x) + intercept, 5)];
};
points = xValues.map(p => predict(p));
this.setData(points, false);
}
}
});

我今天想将其投入生产,但刚刚发现 IE 不支持 ES6。如何重写以删除箭头函数(下面的行)?

      points = xValues.map(p => predict(p));

最佳答案

怎么样

points = xValues.map(function(p) { return predict(p); });

关于javascript - 如何删除此代码中 ES6 箭头函数的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46941223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com