Miss any of our Open RFC calls?Watch the recordings here! »

robin-js

1.0.5 • Public • Published

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

Install

npm i robin-js

DownloadsWeekly Downloads

11

Version

1.0.5

License

MIT

Unpacked Size

10.7 kB

Total Files

6

Last publish

Collaborators

  • avatar