Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created September 23, 2013 22:08
Show Gist options
  • Save hayduke19us/6677643 to your computer and use it in GitHub Desktop.
Save hayduke19us/6677643 to your computer and use it in GitHub Desktop.
def sort some_array
recursive_sort some_array, []
end
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
def build_an_array
original_array = []
while true
puts "Enter a word please"
word = gets.chomp
original_array << word unless word.empty?
if word.empty?
break
end
end
original_array = original_array.compact
sort original_array
end
empty = []
frog = ["frank", "listen", "laugh", "a"]
recursive_sort frog, empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment