tic-tac-toe.js
// or null if the game is not over
or null if the game is not over
or null if the game is not over
function checkWinner (board) {
  for (let i = 0; i < winningCoords.length; i++) {
    if (checkCoords(board, 'O', winningCoords[i])) {
      return {
        coords: winningCoords[i],
        player: 'O'
      }
    } else if (checkCoords(board, 'X', winningCoords[i])) {
      return {
        coords: winningCoords[i],
        player: 'X'
      }
    }
  }
  if (board.join('').length === 9) {
    return 'tie'
  }
  return null
}
function checkWinner ( board ) { for ( let i = 0 ; i < winningCoords . length ; i ++ ) { if ( checkCoords ( board , 'O' , winningCoords [ i ] ) ) { return { coords : winningCoords [ i ] , player : 'O' } } else if ( checkCoords ( board , 'X' , winningCoords [ i ] ) ) { return { coords : winningCoords [ i ] , player : 'X' } } } if ( board . join ( '' ) . length === 9 ) { return 'tie' } return null }
or null if the game is not over
or null if the game is not over
// check for winning conditions // check for a tie