Array.prototype.shuffle = function () {
- return this.sort(() => {return .5 - Math.random()});
+ for (let i = this.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1)); // random index 0..i
+ [this[i], this[j]] = [this[j], this[i]]; // swap elements
+ }
+ return this;
};
class WordQuiz {