source: imaps-frontend/node_modules/lodash-es/_shuffleSelf.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 687 bytes
RevLine 
[d565449]1import baseRandom from './_baseRandom.js';
2
3/**
4 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
5 *
6 * @private
7 * @param {Array} array The array to shuffle.
8 * @param {number} [size=array.length] The size of `array`.
9 * @returns {Array} Returns `array`.
10 */
11function shuffleSelf(array, size) {
12 var index = -1,
13 length = array.length,
14 lastIndex = length - 1;
15
16 size = size === undefined ? length : size;
17 while (++index < size) {
18 var rand = baseRandom(index, lastIndex),
19 value = array[rand];
20
21 array[rand] = array[index];
22 array[index] = value;
23 }
24 array.length = size;
25 return array;
26}
27
28export default shuffleSelf;
Note: See TracBrowser for help on using the repository browser.