Skip to content

Returns a new array with random unique items from an array.

License

Notifications You must be signed in to change notification settings

engvik/random-items

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: []

About

Returns a new array with random unique items from an array.

Resources

License

Stars

Watchers

Forks

Packages

No packages published