Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 358 Bytes

File metadata and controls

19 lines (14 loc) · 358 Bytes

shuffleArray()

Overview

Shuffles the elements of an array randomly.

Code

A screenshot of the titular code snippet

const shuffleArray = (array) => {
  array.forEach((_, i, arr) => {
    const j = Math.floor(Math.random() * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]];
  });
  return array;
};