Created
January 1, 2021 04:15
-
-
Save PAEz/773e09eb758aedfe61aa66c8618a9934 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
var arrayToShuffle= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; | |
arrayToShuffle.forEach((el,index,arr) => { | |
var randomIndex=index; | |
while(randomIndex==index && arr.length>1) randomIndex = Math.floor(Math.random() * arr.length); | |
[arr[index],arr[randomIndex]] = [arr[randomIndex],arr[index]]; | |
}) | |
console.log(arrayToShuffle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment