1.0.0 • Published 7 years ago

wror v1.0.0

Weekly downloads
12
License
MIT
Repository
github
Last release
7 years ago

view on npm downloads per month node version build status test coverage license

Weighted Round-Robin Arbiter

Generate array indices with round-robin distribution, weighted by given scores.

Usage

The package exposes a factory function which takes an array of weight scores and returns the arbiter function.

const wror = require('./'),
      next = wror([ 2, 5, 3 ]),
      counts = [ 0, 0, 0 ],
      order = []

for (let i = 0; i < 10; i++) {
    let n = next()

    counts[ n ]++
    order.push(n)
}

console.log(counts)
console.log(order.join(''))

The result will be the following:

[ 2, 5, 3 ]
1112120120

Installation

With npm:

npm install wror

Tests & benchmarks

Run unit tests:

npm test

Run unit tests and create coverage report:

npm run cover

License

MIT