Last active
December 14, 2015 14:48
-
-
Save astamm78/5102980 to your computer and use it in GitHub Desktop.
A method to sort an array, using a recursive method
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
| def sorter(array) | |
| working = array.clone | |
| self.rec_sort(working, []) | |
| end | |
| def rec_sort(unsorted, sorted) | |
| while unsorted.length > 0 | |
| value = unsorted.inject do |first, second| | |
| first < second ? first : second | |
| end | |
| sorted.push(value) | |
| unsorted.delete(value) | |
| unsorted.rec_sort(unsorted, sorted) | |
| end | |
| return sorted | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment