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?
In
d2function you have this line inforloop:So it is assumed that
rdListis 2 elements at least, but you have only one forbob.Maybe it have to be
rdList[i]?