@jeanfredrik/tictactoe

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @jeanfredrik/tictactoe

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

3.92 kB

Total Files

6

Last publish

Collaborators

  • jeanfredrik