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

Function shuffle

lib/web/jshint.js:8447–8462  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 1

sampleFunction · 0.85

Calls 2

toIterableFunction · 0.85
baseRandomFunction · 0.85

Tested by

no test coverage detected