Created
November 10, 2019 20:12
-
-
Save yrtimiD/f1e260eb5b0c65a79dbc8f3269d77ad3 to your computer and use it in GitHub Desktop.
Shuffle array in javascript
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 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