Sorting an array w multiple values

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

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

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

David

--
Q. What's a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    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.rubypal.com)

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.html#rassoc

best,
                        UG

···

---
Uma Geller

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

···

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.com/black\)
    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.rubypal.com)
---2049402039-1722804141-1166459366=:5255--

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

joos

···

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.html#rassoc

best,
                        UG
---
Uma Geller
http://umageller.wordpress.com