Tic-Tac-Toe

Published by Matt in

Create a function that takes a Tic-tac-toe board and returns "X" if the X's are placed in a way that there are three X's in a row or returns "O" if there are three O's in a row.

Examples

who_won([
  ["O", "X", "O"],
  ["X", "X", "O"],
  ["O", "X", "X"]
]) ➞ "X"

who_won([
  ["O", "O", "X"],
  ["X", "O", "X"],
  ["O", "X", "O"]
]) ➞ "O"

Notes

  • There are no Ties.
  • All places on the board will have either "X" or "O".
  • Check Resources for more info.
Watch a quick demo on how Edabit works.