traxxx/src/utils/shuffle.js

15 lines
310 B
JavaScript
Raw Normal View History

2020-03-23 00:43:49 +00:00
'use strict';
function shuffle(array) {
const shuffledArray = [...array];
2020-03-23 00:43:49 +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
return shuffledArray;
2020-03-23 00:43:49 +00:00
}
module.exports = shuffle;