Skip to content

egoist/random-pick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Pick random unique items from an array.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published