UNPKG

arcade-physics

Version:
34 lines 971 B
"use strict"; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Shuffle = void 0; /** * Shuffles the contents of the given array using the Fisher-Yates implementation. * * The original array is modified directly and returned. * * @function Phaser.Utils.Array.Shuffle * @since 3.0.0 * * @generic T * @genericUse {T[]} - [array,$return] * * @param {T[]} array - The array to shuffle. This array is modified in place. * * @return {T[]} The shuffled array. */ const Shuffle = array => { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); const temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }; exports.Shuffle = Shuffle; //# sourceMappingURL=Shuffle.js.map