mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-12-21 04:52:30 -05:00
590f505a61
This reverts commit1b1b396e92
, reversing changes made toa144bab0e6
.
19 lines
481 B
JavaScript
19 lines
481 B
JavaScript
/*
|
|
* Function that shuffles an array using a Fisher-Yates shuffle.
|
|
*/
|
|
module.exports.shuffle = arr => {
|
|
let i = 0;
|
|
let j = 0;
|
|
let temp = null;
|
|
if (arr) {
|
|
const tempArray = arr.slice(0);
|
|
for (i = arr.length - 1; i > 0; i -= 1) {
|
|
j = Math.floor(Math.random() * (i + 1));
|
|
temp = tempArray[i];
|
|
tempArray[i] = tempArray[j];
|
|
tempArray[j] = temp;
|
|
}
|
|
return tempArray;
|
|
}
|
|
return arr;
|
|
};
|