1 var baseRandom = require('../internal/baseRandom'),
2 toIterable = require('../internal/toIterable');
5 * Creates an array of shuffled values, using a version of the
6 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
10 * @category Collection
11 * @param {Array|Object|string} collection The collection to shuffle.
12 * @returns {Array} Returns the new shuffled array.
15 * _.shuffle([1, 2, 3, 4]);
18 function shuffle(collection) {
19 collection = toIterable(collection);
22 length = collection.length,
23 result = Array(length);
25 while (++index < length) {
26 var rand = baseRandom(0, index);
28 result[index] = result[rand];
30 result[rand] = collection[index];
35 module.exports = shuffle;