snip…
a shorter one (not tested)
#create a hash of firstKey containing array of k2
top={}
unsorted.each{|k1, k2|
if top[k1]
top[k1] << k2
else
top[k1] = [k2]
end
}
sorted =
top.sort.each{|k1, ak2|
ak2.sort.each {|k2|
sorted << [k1, k2]
}
}
p sorted
YS.
Hi Yohanes,
I couldn’t get that to work. unsorted is an array of hashes so the each
method will only return 1 element.
regards,
Martin
···
-----Original Message-----
From: Yohanes Santoso
To: ruby-talk@ruby-lang.org
Sent: 11/10/2002 10:49 AM
Subject: Re: Sorting an array of hashes