开发者

Operation on an array returns NaN if array length is 1

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.ma开发者_运维问答p() or zip or any composition of those kinds of functions?

You can see ALL of the code here -- it's about 60 LOC


In d2 function you have this line in for loop:

tempSum += Math.pow(this.g(rdList[1]), 2) * tempE * (1 - tempE);

So it is assumed that rdList is 2 elements at least, but you have only one for bob.

Maybe it have to be rdList[i]?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜