Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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