Need sort help

S

Stefano Crocco

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
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
 
J

Joost Diepenmaat

jazzez ravi said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,189
Messages
2,571,016
Members
47,618
Latest member
Leemorton01

Latest Threads

Top