export function determineTicTacToeWinner(board: string[][]): string {
for (let i = 0; i < 3; i++) {
if (board[i][0].toLowerCase() === 'x' && board[i][1].toLowerCase() === 'x' && board[i][2].toLowerCase() === 'x' ||
board[0][i].toLowerCase() === 'x' && board[1][i].toLowerCase() === 'x' && board[2][i].toLowerCase() === 'x' ||
board[0][0].toLowerCase() === 'x' && board[1][1].toLowerCase() === 'x' && board[2][2].toLowerCase() === 'x' ||
board[0][2].toLowerCase() === 'x' && board[1][1].toLowerCase() === 'x' && board[2][0].toLowerCase() === 'x') {
return 'X';
}
if (board[i][0].toLowerCase() === 'o' && board[i][1].toLowerCase() === 'o' && board[i][2].toLowerCase() === 'o' ||
board[0][i].toLowerCase() === 'o' && board[1][i].toLowerCase() === 'o' && board[2][i].toLowerCase() === 'o' ||
board[0][0].toLowerCase() === 'o' && board[1][1].toLowerCase() === 'o' && board[2][2].toLowerCase() === 'o' ||
board[0][2].toLowerCase() === 'o' && board[1][1].toLowerCase() === 'o' && board[2][0].toLowerCase() === 'o') {
return 'O';
}
}
return 'Draw game';
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { determineTicTacToeWinner } from "./solution";
// TODO Add your tests here
describe("example", function() {
it("check for winners", function() {
assert.strictEqual(determineTicTacToeWinner([['X', 'X', 'X'], ['X', 'O', 'O'], ['', 'O', 'O']]), 'X');
assert.strictEqual(determineTicTacToeWinner([['O', '', 'O'], ['', 'X', 'O'], ['X', 'X', 'O']]), 'O');
assert.strictEqual(determineTicTacToeWinner([['X', '', 'O'], ['O', 'X', 'O'], ['', '', 'X']]), 'X');
assert.strictEqual(determineTicTacToeWinner([['O', 'O', 'X'], ['X', 'X', 'O'], ['X', 'X', 'O']]), 'X');
assert.strictEqual(determineTicTacToeWinner([['X', 'O', 'X'], ['O', 'O', 'O'], ['X', 'X', 'O']]), 'O');
});
});