_.sampleSize

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

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]
doc_Lodash
2016-11-27 16:40:14
Comments
Leave a Comment

Please login to continue.