UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

26 lines (25 loc) 687 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shuffleSelf = void 0; const baseRandom_1 = require("./baseRandom"); /** * @ignore * @private * @param array * @param size */ function shuffleSelf(array, size) { let index = -1; const length = array.length; const lastIndex = length - 1; size = size === undefined ? length : size; while (++index < size) { const rand = (0, baseRandom_1.baseRandom)(index, lastIndex), value = array[rand]; array[rand] = array[index]; array[index] = value; } array.length = size; return array; } exports.shuffleSelf = shuffleSelf; exports.default = shuffleSelf;