Created
January 5, 2014 12:15
-
-
Save anonymous/8267540 to your computer and use it in GitHub Desktop.
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
def sort arr | |
rec_sort arr, [] | |
end | |
def rec_sort unsorted, sorted | |
if unsorted.length <= 0 | |
return sorted | |
end | |
smallest = unsorted.pop | |
still_unsorted = [] | |
unsorted.each do |tested_object| | |
if tested_object < smallest | |
still_unsorted.push smallest | |
smallest = tested_object | |
else | |
still_unsorted.push tested_object | |
end | |
end | |
sorted.push smallest | |
rec_sort still_unsorted, sorted | |
end | |
puts(sort(['can', 'feel', 'singing', 'like', 'a', 'can'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment