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
- Host: GitHub
- URL: https://github.com/paraself/random-weight
- Owner: paraself
- Created: 2019-04-17T15:21:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-18T15:00:26.000Z (almost 7 years ago)
- Last Synced: 2025-02-23T08:49:41.888Z (12 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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')
```