Need sort help

Hi All,

a=[[“raja”,1],[“Arun”,5],[“babu”,3]]

I want to sort 1,3,5

So i expect output in this order --> raja, babu, arun

Any methods available for this ?

Regards,
P.Raveendran
RF,Chennai

On Tuesday 12 August 2008, jazzez ravi wrote:

Regards,
P.Raveendran
RF,Chennai
http://raveendran.wordpress.com

a.sort_by{|i| i[1]}

Array#sort_by calls the block for each element of the array, and uses
the
return value as a key to use in sorting.

I hope this helps

Stefano

jazzez ravi [email protected] writes:

Hi All,

a=[[“raja”,1],[“Arun”,5],[“babu”,3]]

I want to sort 1,3,5

So i expect output in this order --> raja, babu, arun

Any methods available for this ?

[[“raja”,1],[“Arun”,5],[“babu”,3]].sort {|a,b| a[1] <=> b[1] };

Cheers,
J.

Hi Stefano,

a.sort_by{|i| i[1]}

Array#sort_by calls the block for each element of the array, and uses
the
return value as a key to use in sorting.

I hope this helps

Stefano

Thanks for quick and best reply…

Regards,
P.Raveendran
RF,Chennai

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs