Last active
July 12, 2017 09:53
-
-
Save mess110/fd6133ee1a142944a895 to your computer and use it in GitHub Desktop.
Random Sort
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
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| class Array | |
| def sorted? | |
| self.sort == self | |
| end | |
| def random_sort! | |
| while !self.sorted? | |
| self.shuffle! | |
| end | |
| self | |
| end | |
| end | |
| p [5, 2, 7, 1].random_sort! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment