2006/6/30, Dark Ambient <sambient / gmail.com>: > On 6/29/06, James Edward Gray II <james / grayproductions.net> wrote: > > > #!/usr/local/bin/ruby -w > > > > def sort(array) > > recursive_sort(array, []) > > end > > > > def recursive_sort(unsorted, sorted) > > # find the lowest element > > lowest = nil > > unsorted.each do |item| > > This line (following) is the one that hung me. > > > if lowest == nil || item < lowest > > After many iterations of various attempts, embarassingly I picked the > worst and most incomplete to post. I get it now somewhat, though the > 'aha!' moment is still not hitting. I'll attempt to analyze. Your > looking for the item that is smaller (or less then) then nil. How can > any of the items be smaller then nil ? I know I'm missing something > here, but my thoughts were locked into comparing item < item, No, precedence is first == and < then ||. So this code checks whether either lowest hasn't been set to something meaningful (i.e. not nil) *or* the current item is smaller than the current min. Never compare a boolean with a boolean to get a boolean value. Use boolean logic: if !added and item == lowest > > if added == false and item == lowest Comparing with false and true is especially problematic in Ruby because there are multiple values which are interpreted as "true" and "false". Especially these will break x=1 if x == true x=nil if x == false Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/