Pick random unique items from an array.
$ npm install --save random-pick
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>']
Type: array
string
object
The array or string or array-like object to pick from.
Type: number
Default: 1
The amount of items you wanna pick.
Type: array
Return the picked items.
MIT © EGOIST