MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / sample

Function sample

lib/web/jshint.js:8422–8431  ·  view source on GitHub ↗

* Gets a random element or `n` random elements from a collection. * * @static * @memberOf _ * @category Collection * @param {Array|Object|string} collection The collection to sample. * @param {number} [n] The number of elements to sample. * @param- {Object} [guard]

(collection, n, guard)

Source from the content-addressed store, hash-verified

8420 * // => [3, 1]
8421 */
8422 function sample(collection, n, guard) {
8423 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
8424 collection = toIterable(collection);
8425 var length = collection.length;
8426 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
8427 }
8428 var result = shuffle(collection);
8429 result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
8430 return result;
8431 }
8432
8433 /**
8434 * Creates an array of shuffled values, using a version of the

Callers 1

runInContextFunction · 0.85

Calls 4

isIterateeCallFunction · 0.85
toIterableFunction · 0.85
baseRandomFunction · 0.85
shuffleFunction · 0.85

Tested by

no test coverage detected