Skip to content

Sample random unique values from an array

License

Notifications You must be signed in to change notification settings

jgullstr/array-unique-sampler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

array-unique-sampler GitHub license

Sample random unique values from an array.

Usage

import uniqueSampler from 'array-unique-sampler';

const array = ['a','b','c'];

// Sample single values.
const sample = uniqueSampler(array);

sample() // 'b'
sample() // 'a'
sample() // 'c'
sample() // All values sampled, throws error.

// Sample several values.
const samples = Array.from({length: 2}, uniqueSampler(array)) // ['c', 'b']

About

Sample random unique values from an array

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published