Tic-Tac-Toe

Published by Mubashir Hassan 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

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

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

whoWon([
  ["O", "O", "X"],
  ["X", "X", "O"],
  ["O", "X", "O"]
]) ➞ "Tie"

Notes

  • All places on the board will have either "X" or "O".
  • If both "X" and "O" win, return "Tie".
Watch a quick demo on how Edabit works.