I am trying to match the user input array (this.scoreO, or this scoreX) arrays to the this.winningBoard array, but not with exact values. The values might not be in order, and I want to match the set of three even if there are more values in the "score" array.
So for example, maybe
this.scoreO = [9,5,2,1]
I would like it to trigger a match with [1,5,9] see below array
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]**]
Here is the code:
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
}
}
}
I keep getting a false outcome.