ShufflePolyfill.js 307 B

12345678910
  1. Array.prototype.shuffle = function() {
  2. let currentIndex = this.length, randomIndex;
  3. while (currentIndex != 0) {
  4. randomIndex = Math.floor(Math.random() * currentIndex);
  5. currentIndex--;
  6. [this[currentIndex], this[randomIndex]] = [this[randomIndex], this[currentIndex]];
  7. }
  8. return this;
  9. }