* Creates an array of shuffled values, using a version of the * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). * * @static * @memberOf _ * @category Collection * @param {Array|Object|string} collection The collection to shuffle. * @retu
(collection)
| 8445 | * // => [4, 1, 3, 2] |
| 8446 | */ |
| 8447 | function shuffle(collection) { |
| 8448 | collection = toIterable(collection); |
| 8449 | |
| 8450 | var index = -1, |
| 8451 | length = collection.length, |
| 8452 | result = Array(length); |
| 8453 | |
| 8454 | while (++index < length) { |
| 8455 | var rand = baseRandom(0, index); |
| 8456 | if (index != rand) { |
| 8457 | result[index] = result[rand]; |
| 8458 | } |
| 8459 | result[rand] = collection[index]; |
| 8460 | } |
| 8461 | return result; |
| 8462 | } |
| 8463 | |
| 8464 | /** |
| 8465 | * Gets the size of `collection` by returning its length for array-like |
no test coverage detected