array-unique-sampler
v1.0.2
Published
Sample random unique values from an array.
Downloads
5
Readme
array-unique-sampler
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']