random-items-weight
v1.0.3
Published
Randomly pick a item from an array of items by a weight callback
Downloads
20
Readme
random-items-weight
Randomly pick a item from an array of items by a weight callback
Usage
npm i -S random-items-weight
import rdwt from 'random-items-weight'
let items = [
{
name: 'Alex',
weight: 3
},
{
name: 'John',
weight: 2
},
{
name: 'Tom',
weight: 1
}
]
console.log(rdwt(items,i => i.weight).name,' is picked')