Code Monkey home page Code Monkey logo

robin-js's Introduction

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

robin-js's People

Contributors

pensierinmusica avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.