Created
July 4, 2018 08:39
-
-
Save sean-codes/e70cc7ab2d6d25a83afb53aa66bd6a06 to your computer and use it in GitHub Desktop.
shuffle array
This file contains hidden or 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 arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
function shuffle(arr) { | |
arr.forEach((ele, index) => { | |
var randomIndex = Math.floor(Math.random() * arr.length) | |
arr[index] = arr[randomIndex] | |
arr[randomIndex] = ele | |
}) | |
return arr | |
} | |
console.log(shuffle(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment