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