Skip to content

Instantly share code, notes, and snippets.

@PAEz
Created January 1, 2021 04:15
Show Gist options
  • Save PAEz/773e09eb758aedfe61aa66c8618a9934 to your computer and use it in GitHub Desktop.
Save PAEz/773e09eb758aedfe61aa66c8618a9934 to your computer and use it in GitHub Desktop.
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