Created
September 2, 2021 07:05
-
-
Save YonatanKra/370daff83af96b4621997fcbd423cfb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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