PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/node_modules/lodash/_shuffleSelf.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 28 lines | 16 code | 4 blank | 8 comment | 1 complexity | c86b433c1d9f0f3986297d2cd6020a42 MD5 | raw file
 1var baseRandom = require('./_baseRandom');
 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
28module.exports = shuffleSelf;