1.0.8 • Published 5 years ago

weighted-random-object v1.0.8

Weekly downloads
53
License
GPL-3.0
Repository
github
Last release
5 years ago

weighted-random-object

Get a weighted random object from an array of objects with a weight property.

The objects should have a property with key 'weight' and a numerical value.

Usage

var weightedRandomObject = require("weighted-random-object");

var fruitBasket = [
    {
        "type": "apple",
        "weight": 33
    }, {
        "type": "pear",
        "weight": 66
    }
];

var fruit = weightedRandomObject(fruitBasket);

console.log(fruit.type); // sometimes 'apple', more often 'pear'

Contributing

I appreciate your issues and PRs on Github!

Testing

yarn build && yarn test

Releasing

This project uses np. 1. Make sure your changes are in master 2. Run yarn release 3. Follow the interactive release guide

1.0.8

5 years ago

1.0.7

7 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago