Re: sorting an array w multiple values

From: [email protected] [mailto:[email protected]] On

On Tue, 19 Dec 2006, Josselin wrote:

I understand how to sort an array with a single value but
how can I sort an
array w multiple values : [ integer_value1, float_value2]

sorted_array = an_array.sort_by {|e| e[1] }

And if you want to sort by multiple values, in your own chosen order:

sorted_array = an_array.sort_by{ |e| [ e[1], e[0] ] }

On 2006-12-18 17:55:53 +0100, “Gavin K.” [email protected]
said:

sorted_array = an_array.sort_by{ |e| [ e[1], e[0] ] }

thanks got it too… I think I am strating to understand the logic
behind Ruby structure…
so now I’ll know where to look for before asking … ;-))

… but asking and getting answers help others too…