robin-js
JavaScript utility to create round-robin pairs from a list of participants
Last updated a year ago by pensierinmusica .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install robin-js 
SYNC missed versions from official npm registry.

Robin JS

build status dependencies npm version license

Robin JS is a JavaScript utility to calculate round-robin pairs from a list of participants.

It can be used directly in the browser, as a ES6 module, or as a CommonJS module in Node.

Installation

npm i robin-js

Usage

pairsCalc(participants, [opts])

  • participants (Number, or Array of strings): the number of participants or an array that contains their names.
  • opts (Object, optional)
    • randomStart (Boolean): whether the pairing logic should start from the first participant or a random one (defaults to false).
    • rounds (Number, positive integer): the number of rounds required (defaults to a full round-robin).

Returns an array containing all the rounds. Each round is an array containing all the pairs. Each pair is an array containing the members.

If the number of participants is odd, at each round one different player will be alone (i.e. free / not paired).

Examples

import pairsCalc from 'robin-js';  // ES6
const pairsCalc = require('robin-js'); // CJS

pairsCalc(4);
// [ [ [ 1, 3 ], [ 2, 4 ] ],
//   [ [ 1, 2 ], [ 4, 3 ] ],
//   [ [ 1, 4 ], [ 3, 2 ] ] ]

pairsCalc(['Tom', 'Lucy', 'Hannah']);
// [ [ [ 'Lucy' ], [ 'Tom', 'Hannah' ] ],
//   [ [ 'Tom' ], [ 'Hannah', 'Lucy' ] ],
//   [ [ 'Hannah' ], [ 'Lucy', 'Tom' ] ] ]

MIT License

Current Tags

  • 1.0.5                                ...           latest (a year ago)

7 Versions

  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.0.1-security                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 8
Dependencies (0)
None
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |