Created
September 23, 2013 22:20
-
-
Save hayduke19us/6677776 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 recursive_sort unsorted_array, sorted_array | |
first_word = unsorted_array.first | |
temp = [] | |
temp << first_word | |
unsorted_array.shift | |
unsorted_array.each do |words| | |
if words.length > temp[0].length | |
sorted_array << temp[0] | |
temp.shift | |
elsif | |
unsorted_array << temp[0] | |
temp.shift | |
elsif unsorted_array.count = 1 | |
sorted_array << first_word | |
else unsorted_array.count < 1 | |
return | |
end | |
end | |
if unsorted_array.count > 1 | |
recursive_sort unsorted_array, sorted_array | |
else | |
return | |
puts sorted_array | |
end | |
end | |
empty = [] | |
frog = %w[ lester, friends, hell, ike, i ] | |
recursive_sort frog, empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment