2020-03-23 00:43:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function shuffle(array) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const shuffledArray = [...array];
|
2020-03-23 00:43:49 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
for (let i = array.length - 1; i > 0; i -= 1) {
|
|
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
|
|
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
|
|
}
|
2020-03-23 00:43:49 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return shuffledArray;
|
2020-03-23 00:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = shuffle;
|