Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var sample = require('./sample');
2
3
/** Used as references for `-Infinity` and `Infinity`. */
4
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
5
6
/**
7
* Creates an array of shuffled values, using a version of the
8
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9
*
10
* @static
11
* @memberOf _
12
* @category Collection
13
* @param {Array|Object|string} collection The collection to shuffle.
14
* @returns {Array} Returns the new shuffled array.
15
* @example
16
*
17
* _.shuffle([1, 2, 3, 4]);
18
* // => [4, 1, 3, 2]
19
*/
20
function shuffle(collection) {
21
return sample(collection, POSITIVE_INFINITY);
22
}
23
24
module.exports = shuffle;
25
26