Hi,

Super new to Ruby (learning using the Chris Pine book) and trying to
work through some problems. Right now I'm working on defining a method
for sorting a list of words and have written out what I think to be the
solution to the problem in English. Now I'm translating the English
version section by section and testing my code as I go via running it
and looking for errors.

At this point, I'm having a bit of trouble figuring out the correct /
best way to compare the strings within the original array to each other
and then push the smallest one to the end of the sorted array
(sortarray) and all others to the unsorted array (unsortarray). Any
helpful comments on how to go about making my code up to this point work
correctly?

Thanks a bunch,

Emeka



#Defining method for sorting a list of words

startarray = [] #starting empty array to put strings into
unsortarray = [] #unsorted array - strings are put here after the
initial sort (all sorting takes place from /within here)
sortarray = [] #sorted array - strings are pushed here after being
determined the "smallest" one

request = gets.chomp.downcase #request for words to fill array

while request != '' #check to see if anything to input into array, as
long as there is a string the program keeps requesting input
  startarray.push request #put any input into the end of the starting
empty array
  request = gets.chomp.downcase #requests string to fill array, makes
the string lowercase, and provides information back into conditional
end

startarray.each do |start| #for each string in start array do this
  if start < start #compare each string to other and if the string is
the smallest
  sortarray.push start #push the string to the end of the sorted array
  else
    unsortarray.push start #push all strings that are not the smallest
to the end of the unsorted array
end
end

-- 
Posted via http://www.ruby-forum.com/.