Martin DeMello
6/8/2009 9:03:00 AM
On Mon, Jun 8, 2009 at 2:10 PM, Paganoni<noway@fakenullvoid.com> 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