Skip to content

Instantly share code, notes, and snippets.

@jli-hashrocket
Created September 14, 2013 15:09
Show Gist options
  • Select an option

  • Save jli-hashrocket/6562774 to your computer and use it in GitHub Desktop.

Select an option

Save jli-hashrocket/6562774 to your computer and use it in GitHub Desktop.
Sorting problem in Ch. 12 section Rite of Passage:Sorting
def sort(mylist)
recursive_sort(mylist,[])
end
def recursive_sort(unsorted_array, sorted_array)
if unsorted_array[1] == nil
sorted_array.push unsorted_array[0]
false
elsif unsorted_array[0] == nil
false
elsif unsorted_array[0] < unsorted_array[1]
sorted_array.shift unsorted_array[0]
elsif unsorted_array[1] < unsorted_array[0]
sorted_array.shift unsorted_array[1]
else
end
recursive_sort(unsorted_array, sorted_array)
return sorted_array
end
keeploop = true
wordcollect = []
while keeploop == true
puts "Type a word"
word = gets.chomp
wordcollect.push "#{word}"
if word == ''
wordcollect.pop
sort(wordcollect)
keeploop = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment