【发布时间】:2017-12-11 22:41:03
【问题描述】:
我正在尝试将用户输入数组(this.scoreO 或 this scoreX)数组与 this.winningBoard 数组进行匹配,但不是精确值。这些值可能不按顺序排列,即使“分数”数组中有更多值,我也想匹配三个集合。
例如,也许
this.scoreO = [9,5,2,1]
我希望它触发与 [1,5,9] 的匹配,请参见下面的数组
this.winningBoard = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[3,5,7],**[1,5,9]**]
代码如下:
function Game (player) {
this.winningBoard = [
[1,2,3],
[4,5,6],
[7,8,9],
[1,4,7],
[2,5,8],
[3,6,9],
[3,5,7],
[1,5,9]
]
this.scoreO = [];
this.scoreX = [];
}
Game.prototype.findWinner2 = function() {
for(i = 0; i < this.winningBoard.length; i++) {
if (this.winningBoard[i].includes(this.scoreO) === true) {
//display player 1 "O" is the winner
} else if (this.winningBoard[i].includes(this.scoreX) === true) {
//display player 2 "X" is the winner
}
}
}
我不断得到错误的结果。
【问题讨论】:
标签: javascript arrays oop