Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active April 26, 2022 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/f86853f344101f35c1b23679134b843b to your computer and use it in GitHub Desktop.
Save McLarenCollege/f86853f344101f35c1b23679134b843b to your computer and use it in GitHub Desktop.
Exercise : X win in last column

Given the following board variable representing a tic-tac-toe board. Write a function to check if X has won in the last column. That is, whether all 3 cells in the last column are 'X' Your function should return the correct boolean value for any given board.

CODE TEMPLATE


function hasXWonInLastCol(board) {
//write your code here
}

console.log(hasXWonInLastCol([[' ', 'O', 'X'],['O', 'X', ' '], ['O', ' ', 'X']]));// false
console.log(hasXWonInLastCol([['O', 'X', 'X'],['O', 'X', ' '], ['O', 'X', 'X']]));// false
console.log(hasXWonInLastCol([['X', 'O', 'O'],['O', 'X', 'X'], ['O', ' ', 'X']]));// false
console.log(hasXWonInLastCol([[' ', 'O', 'X'],['O', 'X', 'X'], ['O', ' ', 'X']]));// true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment