# random-wei-element

> Randomly pick a element from an array of objects by a weight callback

Latest version **1.0.1** (published 2023-01-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install random-wei-element
pnpm add random-wei-element
yarn add random-wei-element
bun add random-wei-element
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-01-03 |
| First published | 2023-01-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mspony |

## Links

- npm: https://www.npmjs.com/package/random-wei-element
- npm.io page: https://npm.io/package/random-wei-element

## Recent versions

- 1.0.1 (latest) — 2023-01-03
- 1.0.0 — 2023-01-03

## README

# random-wei-element

参考视频：<https://www.bilibili.com/video/BV1Vb411L7se/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=7a011a30c558fce1fdf65840b5aeff17>

Randomly pick an array item by weight callback

## Usage

``` typescript
import rnd from 'random-wei-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')
```

---
_Source: https://npm.io/package/random-wei-element · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
