mardi 24 août 2021

Calculating the winner in a tic tac game using react hook and js

I am new to javaScript and react hook, working on a tic tac game but I don't understand the below if statement, I need an explanation as to what the if statement is saying in English. my calculate winner function below:

export function calculateWinner(squares) {
    const Lines = [
      [0, 1, 2],
      [3, 4, 5],
      [6, 7, 8],
      [0, 3, 6],
      [1, 4, 7],
      [2, 5, 8],
      [0, 4, 8],
      [2, 4, 6],
    ];
    for (let i = 0; i < Lines.length; i++) {
      const [a, b, c] = Lines[i];
      if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
        return squares[a];
      }
    }
    return null;
  }

Aucun commentaire:

Enregistrer un commentaire