出于某种原因,第二个for
循环从 1 开始。我确实意识到第一个for
循环i
从 1 开始。本来就是这样。然而,即使j
for
循环说从 0 开始,它仍然从 1 开始。
var findWinners = function (playersRay) {
var players = playersRay;
var results = new Array();
//getdealers dealers hand and info
var dealerHand = players[0]
var dealerScore = dealerHand.getScore()
var dealerBust = dealerScore > 21 ? true : false;
//loops through all players; skips dealer (array position 0)
var numPlayers = players.length;
for (var i=1; i<numPlayers; i++) {
//loops through all the players hands.
//player might have more than 1 hand if he splits his cards
var player = players[i];
var numHands = player.length;
results[i] = new Array();
for (var j=0; j<numHands; j++)
var handScore = player[j].getScore();
if (handScore > 21) {
results[i][j] = false;
}
else if (dealerScore > 21) {
results[i][j] = true;
}
else if (handScore > dealerScore) {
results[i][j] = true;
}
else {
results[i][j] = false;
}
}
return results;
}
它返回这个:[undefined, [undefined, true]]
它应该返回这个:[undefined, [true]]
以防万一你想知道。一个示例playersRay
是: [Object, [Object]]
该对象具有关于庄家或玩家的二十一点手的信息。
完整代码链接:https ://docs.google.com/open?id=0BxvwY0fUFc3aMTdTOXU0b0ttamM