如果数组长度为 1,则对数组进行操作将返回 NaN
Player.prototype.d2 = function(ratingList, rdList) {
var tempSum = 0;
for (var i = 0; i < ratingList.length; i++) {
var tempE = this.e(ratingList[i], rdList[i]);
tempSum += Math.pow(this.g(rdList[1]), 2) * tempE * (1 - tempE);
}
return 1 / Math.pow(q, 2) * tempSum;
};
这似乎是有问题的一点。
一切看起来都很好,除非 ratingList 、
rdList 和
outcomeList 仅包含一个值。然后 stuff 被设置为 NaN。我尝试将索引更改为 -1,将比较更改为
ratingList.length - 1
,甚至尝试使用递减的 for
循环,但它似乎总是返回如果数组仅包含一个值,则为 NaN。
有没有什么方法(我确信有 - 我想问题是如何)消除 for
循环并将其替换为 Array.map()
或 zip 或这些函数的任何组合?
Player.prototype.d2 = function(ratingList, rdList) {
var tempSum = 0;
for (var i = 0; i < ratingList.length; i++) {
var tempE = this.e(ratingList[i], rdList[i]);
tempSum += Math.pow(this.g(rdList[1]), 2) * tempE * (1 - tempE);
}
return 1 / Math.pow(q, 2) * tempSum;
};
This seems to be the bit in question.
Everything seems fine unless ratingList
, rdList
and outcomeList
only contain one value. Then stuff gets set to NaN instead. I've tried changing the index to -1, changing the comparison to ratingList.length - 1
, even tried it with a decrementing for
loop, but it always seems to return NaN if the arrays contain only one value.
Is there any way (I'm sure there is -- I guess the question is how) to do away with the for
loop and replace it with Array.map()
or zip or any composition of those kinds of functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 d2 函数中,您在 for 循环中有这一行:
因此假设 rdList 至少有 2 个元素,但只有一个 for鲍勃。
也许它必须是
rdList[i]
?In
d2
function you have this line infor
loop:So it is assumed that
rdList
is 2 elements at least, but you have only one forbob
.Maybe it have to be
rdList[i]
?