Attempting to match the user input arrays (this.scoreO or this scoreX) with the this.winningBoard array, but not requiring exact values. The order of values may be different and I want to identify a match even if there are additional values in the "score" array.
For instance, consider:
this.scoreO = [9,5,2,1]
I want it to trigger a match with [1,5,9] as shown below:
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]**]
Below is the code snippet:
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
}
}
}
Encountering unexpected outcomes.