[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sorting an array w multiple values

Josselin

12/18/2006 4:21:00 PM

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]

an_array = [ [123, 42.50], [ 245, 25.45], [389, 32.69] ]

wich should give (sorting on the 2nd value)

sorted_array => [[ 245, 25.45],  [389, 32.69], [123, 42.50] ]

thanks for your help

joss

4 Answers

dblack

12/18/2006 4:29:00 PM

0

Uma Geller

12/18/2006 4:30:00 PM

0

> wich should give (sorting on the 2nd value)
>
> sorted_array => [[ 245, 25.45], [389, 32.69], [123, 42.50] ]

would this help ?
http://dev.rubycentral.com/ref/ref_c_array.h...

best,
UG
---
Uma Geller
http://umageller.wor...

Josselin

12/18/2006 10:00:00 PM

0

On 2006-12-18 17:29:29 +0100, dblack@wobblini.net said:

> ---2049402039-1722804141-1166459366=:5255
> Content-Type: MULTIPART/MIXED;
> BOUNDARY="-2049402039-1722804141-1166459366=:5255"
>
> This message is in MIME format. The first part should be readable text,
> while the remaining parts are likely unreadable without MIME-aware tools.
>
> ---2049402039-1722804141-1166459366=:5255
> Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
> Content-Transfer-Encoding: QUOTED-PRINTABLE
>
> Hi --
>
> On Tue, 19 Dec 2006, Josselin wrote:
>
>> I understand how to sort an array with a single value but how can I sort =
> an=20
>> array w multiple values : [ integer_value1, float_value2]
>>
>> an_array =3D [=A0[123, 42.50], [ 245, 25.45], [389, 32.69] ]
>>
>> wich should give (sorting on the 2nd value)
>>
>> sorted_array =3D> [[ 245, 25.45], =A0[389, 32.69], [123, 42.50] ]
>
> sorted_array =3D an_array.sort_by {|e| e[1] }
>
>
> David
>
> --=20
> Q. What's a good holiday present for the serious Rails developer?
> A. RUBY FOR RAILS by David A. Black (http://www.manning...)
> aka The Ruby book for Rails developers!
> Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
> A. Ruby Power and Light, LLC (http://www.r...)
> ---2049402039-1722804141-1166459366=:5255--
> ---2049402039-1722804141-1166459366=:5255--

thanks a lot , got it... written in my secret notebook.... ;-)))

Josselin

12/18/2006 10:01:00 PM

0

On 2006-12-18 17:29:59 +0100, "Uma Geller" <umageller@gmail.com> said:

>> wich should give (sorting on the 2nd value)
>>
>> sorted_array => [[ 245, 25.45], [389, 32.69], [123, 42.50] ]
>
> would this help ?
> http://dev.rubycentral.com/ref/ref_c_array.h...
>
> best,
> UG
> ---
> Uma Geller
> http://umageller.wor...

thanks .. got it .. so many things to think..

joos