An open API service indexing awesome lists of open source software.

https://github.com/paraself/random-weight

Randomly pick an array item by weight callback
https://github.com/paraself/random-weight

Last synced: 11 months ago
JSON representation

Randomly pick an array item by weight callback

Awesome Lists containing this project

README

          

# random-weight
Randomly pick an array item by weight callback

### Usage
```
npm i -S random-weight
```

``` typescript
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')
```