Thank you for your patience. I now get it! As you mentioned previously
the first time through your loop, lowest is nil – which means that the
item < lowest comparison is never evaluated, second iteration (via
lowest =
item) changes it.
Why I didn’t see it then.
lowest = nil <----------- here lowest is being set to nil
list.each do |item|
if lowest == nil || item < lowest <----then expression 1 is true (as
you
say above).
lowest = item
end
end
I might just be missing a brain, because it seems like it’s not sinking
through.
I’m back already :). Basically I’m trying to take James original
recursion
version and do it with recursion. Anyway, my questions are below in the
<---------------- lines.
TIA
Stuart
def sort(list)
sorted = []
unsorted = []
puts 'here is list: ’
puts list <------ Here i’m outputing the list I put in to the method
prints out the entire list
puts
lowest = nil
list.each do |item|
if lowest == nil || item < lowest
lowest = item
end
end
sorted.push(lowest)
make a new unsorted list, minus the low guy
unsorted = [ ]
added = false
list.each do |item|
if added == false and item == lowest
added = true
else
unsorted.push(item)
end
end
puts ‘Here is the unsorted list’
puts unsorted
puts
puts ‘Here is the sorted list’
puts sorted
puts
puts ‘Here is list’ <----------------------- Here though, the list
is
empty (at least of values). Something I don’t get, since I didn’t see
any
.delete
puts
puts 'list size is: '<---------------------------yet here the size
returned is 5 the number of original elements.
puts list.size
third step (from James’ is where he returns control to method (or