The matches calendar generator you have been looking for
Fixture-Generator is a fancy, quick and random generator of matches you can import in your JS code to create a football league, basketball tournament or any other sport in which all the partecipants have to challenge each other.
Under the hood is driven by the Round-robin alghorithm which guarantees thah each contestant meets all other contestants in turn.
I have used this tool during the development of What If. Take a look at it if you are a fantasy football player.
- Package page fixture-generator
- Run the command
npm install fixture-generator
- Download the source code from Github
- Import it into your project
There are actually two ways for generating fixtures:
- Using
generateRandomFixture
. It will return only one random fixture
const { generateRandomFixture } = require('.fixtureGenerator.js')
/*
@param {Array} array The array containing all the attendees
*/
const tournaments = generateRandomFixture([1,2,3,4])
console.log(tournaments)
/*
[
{
name: "MatchDay 1",
value: [
{
teamA: 1,
teamB: 3,
},
{
teamA: 2,
teamB: 4,
},
],
},
{
name: "MatchDay 2",
value: [
{
teamA: 1,
teamB: 2,
},
{
teamA: 4,
teamB: 3,
},
],
},
{
name: "MatchDay 3",
value: [
{
teamA: 1,
teamB: 4,
},
{
teamA: 3,
teamB: 2,
},
],
}
]
*/
generateRandomFixtureFromAllPermutations
takes as argument the number of fixtures you want to generate.
const { generateRandomFixtureFromAllPermutations } = require('.fixtureGenerator.js')
/*
@param {Array} array The array containing all the attendees
@param {Number} n The number of tournaments that needs to be randomly generated
*/
const tournaments = generateRandomFixtureFromAllPermutations([1,2,3,4], 2)
console.log(tournaments)
/*
// First calendar
[.....],
// Second calendar
[
{
name: "MatchDay 1",
value: [
{
teamA: 1,
teamB: 3,
},
{
teamA: 2,
teamB: 4,
},
],
},
{
name: "MatchDay 2",
value: [
{
teamA: 1,
teamB: 2,
},
{
teamA: 4,
teamB: 3,
},
],
},
{
name: "MatchDay 3",
value: [
{
teamA: 1,
teamB: 4,
},
{
teamA: 3,
teamB: 2,
},
],
}
]
*/
- Copyright 2020 © Annino De Petra