Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created September 23, 2013 22:20
Show Gist options
  • Save hayduke19us/6677776 to your computer and use it in GitHub Desktop.
Save hayduke19us/6677776 to your computer and use it in GitHub Desktop.
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