Created
May 4, 2019 08:47
-
-
Save seunggabi/d018657da5b15a4b50ce1693d12446c0 to your computer and use it in GitHub Desktop.
shuffle.js
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
function shuffle(arr) { | |
var i = arr.length; | |
var random; | |
var temp; | |
while (i > 0) { | |
random = Math.floor(Math.random() * i--); | |
temp = arr[i]; | |
arr[i] = arr[random]; | |
arr[random] = temp; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[reference] https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array