From: Michael Neumann Date: 2009-06-09T02:02:16+09:00 Subject: Re: How to sort array ascending, except zero ? Paganoni schrieb: > le 08/06/2009 10:38, Paganoni nous a dit: >> 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 >> >> I really don't see how to do >> >> Thanks for your help > > I forgot to mention that the array can contain several 0 values not only > one. Infinity = 1.0/0.0 [1,4,2,0,8,9].sort_by {|x| x == 0 ? Infinity : x } Or: a = [1,4,2,0,8,9] max = a.max + 1 a.sort_by {|x| x == 0 ? max : x } Regards, Michael