1.0.0 • Published 6 years ago

@jeanfredrik/tictactoe v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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

ParamTypeDescription
empty*The value that represents an empty tile on the board
boardArrayAn array with a length of 9