shuffle.cjs 448 B

1234567891011121314
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.shuffle = shuffle;
  4. function shuffle(array) {
  5. let currentIndex = array.length;
  6. while (currentIndex !== 0) {
  7. const randomIndex = Math.floor(Math.random() * currentIndex);
  8. currentIndex -= 1;
  9. const tmp = array[currentIndex];
  10. array[currentIndex] = array[randomIndex];
  11. array[randomIndex] = tmp;
  12. }
  13. return array;
  14. }