@jeanfredrik/tictactoe
v1.0.0
Published
Utility functions for Tic-Tac-Toe
Downloads
2
Readme
Tic-Tac-Toe utility functions
A minimalistic library for working with Tic-Tac-Toe games
winner(empty)(board)
Finds the winner of a Tic-Tac-Toe game. Tiles are compared with strict equality. Example:
const tictactoe = require('@jeanfredrik/tictactoe')
const getWinner = tictactoe.winner('')
let board = ['x', '', '', 'o', 'x', '', 'o', '', 'x']
/*
|x| | |
|o|x| |
|o| |x|
*/
let winner = getWinner(board)
console.log(winner) // 'x'
Returns: * – The value that appears three times in a row, column or diagonal, or empty
| Param | Type | Description | | ----- | ------------------ | ---------------------------------------------------- | | empty | * | The value that represents an empty tile on the board | | board | Array | An array with a length of 9 |