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;
};
這似乎是有點問題。如果數組長度爲1,則陣列上的操作返回NaN
一切似乎都很好,除非ratingList
,rdList
和outcomeList
只包含一個值。然後東西被設置爲NaN。我試着改變指數爲-1,改變比較ratingList.length - 1
,即使遞減for
循環試過,但它似乎總是返回NaN的,如果陣列中只包含一個值。
有沒有什麼辦法(我敢肯定存在 - 我想問題是如何)取消for
循環,並用Array.map()
或zip或其它任何組合的函數替換它?
You can see ALL of the code here -- it's about 60 LOC
並以 「只包含一個值」 你的意思是:'ratingList = 「OneValue」]'或'ratingList = 「OneValue」'? – Cipi
ratingList = [1400] –