_.sampleSize

_.sampleSize(collection, [n=1])

source npm package

Gets n random elements at unique keys from collection up to the size of collection.

Since

4.0.0

Arguments

  1. collection (Array|Object): The collection to sample.
  2. [n=1] (number): The number of elements to sample.

Returns

(Array): Returns the random elements.

Example

_.sampleSize([1, 2, 3], 2);
// => [3, 1]
 
_.sampleSize([1, 2, 3], 4);
// => [2, 3, 1]