JSFiddle - React, Tailwind, and code Playground
JavaScript
class ShufflableArray extends Array {
shuffle() {
const copy = [...this];
let index = 0;
while (copy.length > 0) {
const copyIndex = Math.floor(Math.random() * copy.length);
this[index] = copy.splice(copyIndex, 1)[0];
index++;
}
}
}
lelele = new ShufflableArray(1, 2, 3, 4, 5);
lelele.shuffle();
console.log(lelele);