From: Dark Ambient Date: 2006-07-10T01:16:55+09:00 Subject: Re: Sorting arrays ------=_Part_129759_5021386.1152461806778 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline David, 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. Apologies Stuart On 7/9/06, dblack@wobblini.net wrote: > > Hi -- > > On Mon, 10 Jul 2006, Dark Ambient wrote: > > > On 7/9/06, dblack@wobblini.net wrote: > > > >> I don't see that in your code. I see this: > >> > >> lowest = nil > >> > >> So this: > >> > >> lowest == nil > >> > >> is true. > > > > > > Sorry I'm not trying to be frustrating. > > > > def sort(list) > > sorted = [] > > unsorted = [] > > > > 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). > > Correct. Therefore this gets executed: > > > lowest = item > > So now, lowest is item -- which was "five" (or whatever the first > array item was). > > So *next* time through the loop, this: > > lowest == nil > > will *not* be true. So this: > > item < lowest > > will be tested instead. > > > David > > -- > http://www.rubypowerandlight.com => Ruby/Rails training & consultancy > http://www.manning.com/black => RUBY FOR RAILS, the Ruby book for > Rails developers > http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log > dblack@wobblini.net => me > > ------=_Part_129759_5021386.1152461806778--