Last active
March 24, 2019 05:50
-
-
Save xingoxu/c31cf15e5daad2e170f096847fe11ff3 to your computer and use it in GitHub Desktop.
use CLRS RANDOMIZE-IN-PLACE
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
| Array.prototype.shuffle = function shuffle() { | |
| for (let i = 0; i < this.length; i++){ | |
| let randomI = Math.floor(Math.random() * (this.length - i)) + i; | |
| let temp = this[i]; | |
| this[i] = this[randomI]; | |
| this[randomI] = temp; | |
| } | |
| return this; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment