1.2.4 • Published 11 months ago

round-robin-tournament v1.2.4

Weekly downloads
5
License
MIT
Repository
github
Last release
11 months ago

CI

Round-robin tournament

A round-robin tournament (or all-play-all tournament) using JavaScript / TypeScript. The goal is to create a competition in which each team meets the other teams in two rounds.

How to Use It

Install from npm:

npm i round-robin-tournament

Import round-robin-tournament and pass an Array to constructor. Use the matches method to get the fixture.

import Tournament from 'round-robin-tournament'

const TEAMS = [
  { id: 1, name: 'Arsenal' },
  { id: 2, name: 'Chelsea' },
  { id: 3, name: 'Liverpool' },
  { id: 4, name: 'Manchester City' },
  { id: 5, name: 'Manchester United' },
  { id: 6, name: 'West Ham' },
]

const tournament = new Tournament(TEAMS)
const matches = tournament.matches

Result example

  • The matches method returns and Array of rounds
  • Each round is an Array of matches
  • Each match is an Array of two teams: [{ home } , { visitor/away }]
[
  ...
  [
    [ { id: 1, name: 'Arsenal' }, { id: 5, name: 'Manchester United' } ],
    [ { id: 6, name: 'West Ham' }, { id: 2, name: 'Chelsea' } ],
    [ { id: 3, name: 'Liverpool' }, { id: 4, name: 'Manchester City' } ]
  ]
  ...
]

Caveat

If you are not using a transpiler or importing using require via CommonJS, you may need to access the default reference.

const Tournament = require('./tournament.js').default
1.2.4

11 months ago

1.2.3

3 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.2.1

4 years ago

1.0.0

4 years ago