1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 08:10:18 +00:00
musix-oss/struct/funcs/shuffle.js
2020-02-10 21:08:46 +02:00

11 lines
313 B
JavaScript

module.exports = function (a) {
for (let i = a.length - 1; i > 1; i--) {
const j = Math.floor(Math.random() * (i + 1));
if (i === 0 || j === 0) {
console.log(`J or I is 0. I: ${i} J: ${j}`);
} else {
[a[i], a[j]] = [a[j], a[i]];
}
}
return a;
};