Created
March 10, 2016 07:52
-
-
Save nijitaro/1d08a1b03bea5d66b08d to your computer and use it in GitHub Desktop.
Shuffle Array
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
const shuffle = arr => { | |
var i, j, temp; | |
arr = arr.slice(); | |
i = arr.length; | |
if (i === 0) { | |
return arr; | |
} | |
while (--i) { | |
j = Math.floor(Math.random() * (i + 1)); | |
temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
return arr; | |
} | |
export default shuffle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment