1 | import sampleSize from './sampleSize';
|
2 |
|
3 | /** Used as references for the maximum length and index of an array. */
|
4 | var MAX_ARRAY_LENGTH = 4294967295;
|
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 | * @since 0.1.0
|
13 | * @category Collection
|
14 | * @param {Array|Object} collection The collection to shuffle.
|
15 | * @returns {Array} Returns the new shuffled array.
|
16 | * @example
|
17 | *
|
18 | * _.shuffle([1, 2, 3, 4]);
|
19 | * // => [4, 1, 3, 2]
|
20 | */
|
21 | function shuffle(collection) {
|
22 | return sampleSize(collection, MAX_ARRAY_LENGTH);
|
23 | }
|
24 |
|
25 | export default shuffle;
|