← Back to challenges

O's and X's

JavaScriptHardgamesarrays

Instructions

Given an array containing three strings, representing the rows of an O's and X's board from top to bottom, return the row and column position of the winning move for X's. Return false if the game cannot be won.

Examples

XAndO(board = [" | | ", " |X| ", "X| | "]) ➞  [1, 3]

// Board becomes:
//    |   |
//    |X |
// X |   |

XAndO(board = ["X|X|O", "O|X| ", "X|O| "]) ➞ [3, 3]

// Board becomes:
// X|X|O
// O|X|
// X|O|

Notes

There is no 0 index for the row or column.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.