1.0.0 • Published 2 years ago

@bluepostit/round-robin v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Round Robin Scheduler

Given an array of players, the schedule function returns an array of pairings, such that each player is paired with every other player.

This is a translation from Ruby into JavaScript of @ssaunier's Round Robin Tournament.

Usage

const schedule = require('@bluepostit/round-robin')

const colors = ['red', 'orange', 'yellow', 'green']
const colorPairings = schedule(colors)
console.log(colorPairings)

// Output should be:
[
  [ [ 'red', 'orange' ], [ 'yellow', 'green' ] ],
  [ [ 'yellow', 'orange' ], [ 'green', 'red' ] ],
  [ [ 'green', 'orange' ], [ 'red', 'yellow' ] ]
]


const teams = ['first', 'second', 'third']
const teamPairings = schedule(teams)
console.log(teamPairings)

// Output should be
[
  [ [ 'first', 'second' ], [ 'third', null ] ],
  [ [ 'third', 'second' ], [ null, 'first' ] ],
  [ [ null, 'second' ], [ 'first', 'third' ] ]
]