random-pick
Pick random unique items from an array.
Last updated 5 years ago by kchan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install random-pick 
SYNC missed versions from official npm registry.

random-pick NPM version NPM downloads Build Status

Pick random unique items from an array.

Install

$ npm install --save random-pick

Usage

const pick = require('random-pick')

const fruits = [
  'apple',
  'banana',
  'peach',
  'mango'
]

pick(fruits)
//=> ['banana']

pick(fruits, 2)
//=> ['apple', 'peach']

pick('hello world', 4)
//=> ['e', 'h', 'r', 'w']

pick(document.querySelectorAll('.item'), 2)
//=> ['<div class="item">...</div>', '<div class="item">...</div>']

API

randomPick(input[, count])

input

Type: array string object

The array or string or array-like object to pick from.

count

Type: number
Default: 1

The amount of items you wanna pick.

return

Type: array

Return the picked items.

License

MIT © EGOIST

Current Tags

  • 0.1.1                                ...           latest (5 years ago)

2 Versions

  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |