random-weighted-element
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

random-weight-element

Randomly pick an array item by weight callback

Usage

import rnd form 'random-weight-element'
let items = [
    {
        name: "Alex",
        weight: 1
    },
    {
        name: "Jonny",
        weight: 2
    },
    {
        name: "Tom",
        weight: 3
    }
];

console.log(rnd(items,i=>i.weight).name,"is picked!");

Readme

Keywords

none

Package Sidebar

Install

npm i random-weighted-element

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

10.3 kB

Total Files

8

Last publish

Collaborators

  • wjf1616