Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created September 2, 2021 07:05
Show Gist options
  • Save YonatanKra/370daff83af96b4621997fcbd423cfb9 to your computer and use it in GitHub Desktop.
Save YonatanKra/370daff83af96b4621997fcbd423cfb9 to your computer and use it in GitHub Desktop.
function scrambleArray(arr) {
const tmpArray = Array.from(arr);
const scrambledArray = new Array(arr.length).fill(1);
let index = 0;
while (tmpArray.length) {
const randomIndex = Math.floor(Math.random() * (tmpArray.length - 1));
scrambledArray[index++] = tmpArray.splice(randomIndex, 1)[0];
}
return scrambledArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment