Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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