Skip to content

Instantly share code, notes, and snippets.

@sean-codes
Created July 4, 2018 08:39
Show Gist options
  • Save sean-codes/e70cc7ab2d6d25a83afb53aa66bd6a06 to your computer and use it in GitHub Desktop.
Save sean-codes/e70cc7ab2d6d25a83afb53aa66bd6a06 to your computer and use it in GitHub Desktop.
shuffle array
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