forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShuffle.js
More file actions
32 lines (29 loc) · 815 Bytes
/
Shuffle.js
File metadata and controls
32 lines (29 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* 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
*
* @param {array} array - The array to shuffle. This array is modified in place.
*
* @return {array} The shuffled array.
*/
var Shuffle = function (array)
{
for (var i = array.length - 1; i > 0; i--)
{
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
};
module.exports = Shuffle;