From: Martin DeMello Date: 2009-06-08T18:03:00+09:00 Subject: Re: How to sort array ascending, except zero ? On Mon, Jun 8, 2009 at 2:10 PM, Paganoni wrote: > Hello, I need to sort > [1,4,2,0,8,9] to [1,2,4,8,9,0] > > A simple ascending sort but with the zero values to the end max = a.max + 1 # or max = 2 ** 31, say, if you don't want the extra pass # but sorting is O(n log n) and max is O(n) so it doesn't really matter a.sort_by {|x| x.zero? ? max : x} martin