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
···
--
Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.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
On Tuesday 12 August 2008, jazzez ravi wrote:
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
jazzez ravi <jazzezravi@gmail.com> 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.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
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
--
Posted via http://www.ruby-forum.com/\.