random-items

1.0.3 • Public • Published

random-items

A function that returns a new array with random unique items from an array.

Install

npm install random-items

Usage example

import randomItems from 'random-items';
 
const array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
 
randomItems(array, 1);  // Output: [ 3 ]
randomItems(array, 2);  // Output: [ 4, 5 ]
randomItems(array, 4);  // Output: [ 9, 5, 6, 0 ]
randomItems(array, 11); // Output: Error: Not long enough array to return 11 random elements.
randomItems(array, 0);  // Output: []
randomItems(array);     // Output: []

Dependents (1)

Package Sidebar

Install

npm i random-items

Weekly Downloads

3

Version

1.0.3

License

MIT

Last publish

Collaborators

  • engvik