Last active
February 1, 2017 15:45
-
-
Save oboshto/7e6fe59c47b166ecb9da419d67b7c979 to your computer and use it in GitHub Desktop.
array shuffle
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
| let shuffle = function (array) { | |
| for (let i = array.length - 1; i > 0; i -= 1) { | |
| let j = Math.floor(Math.random() * (i + 1)); | |
| let temp = array[i]; | |
| array[i] = array[j]; | |
| array[j] = temp; | |
| } | |
| return array; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment