random-gxy
v1.0.1
Published
Randomly pick a element from an array of objects by a weight callback
Downloads
2
Readme
random-gxy
Randomly pick an array item by weight callback
Usage
import rnd from 'random-gxy'
let items = [
{
name: 'Alex',
weight: 1,
count: 0
},
{
name: 'Jonny',
weight: 2,
count: 0
},
{
name: 'Tom',
weight: 3,
count: 0
}
]
console.log(rnd(items), i => i.weight).name, 'is picked');