Skip to content

Instantly share code, notes, and snippets.

@yrtimiD
Created November 10, 2019 20:12
Show Gist options
  • Save yrtimiD/f1e260eb5b0c65a79dbc8f3269d77ad3 to your computer and use it in GitHub Desktop.
Save yrtimiD/f1e260eb5b0c65a79dbc8f3269d77ad3 to your computer and use it in GitHub Desktop.
Shuffle array in javascript
function shuffle(arr){
let shuffle = [];
while(arr.length>0){
const r = Math.floor(Math.random()*arr.length);
shuffle.push(arr.splice(r,1)[0]);
}
return shuffle;
}
const list = [1,2,3,4,5,6,7,8,9];
console.log(shuffle(list));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment