shuffle.js 351 B

1234567891011
  1. export function shuffle(array) {
  2. let currentIndex = array.length;
  3. while (currentIndex !== 0) {
  4. const randomIndex = Math.floor(Math.random() * currentIndex);
  5. currentIndex -= 1;
  6. const tmp = array[currentIndex];
  7. array[currentIndex] = array[randomIndex];
  8. array[randomIndex] = tmp;
  9. }
  10. return array;
  11. }