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