@jeanfredrik/tictactoe

v1.0.0
Utility functions for Tic-Tac-Toe

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
npm i @jeanfredrik/tictactoe

Metadata

  • ISC
  • Whatever
  • Unknown
  • released 6/14/2018

Downloads

Maintainers