Quick Prototype.js hash question. Given: MyHash = {"Alpha" : {name:"Foo",val:3}, "Delta" : {name:"Bar",val:2}, "Beta" : {name:"Baz",val:4} } I want to display this set ordered by key - Alpha,Beta,Delta and by val - 2,3,4 Prototype.js helps with the hash: $H(MyHash).keys().sort() will give me Alpha, Beta, Delta but I''ve not figured out how to extract the keys in sorted order "Delta,Alpha,Beta" according to val. Thoughts? --Mike Nosal mnosal-AZamIotjMK3YtjvyW6yDsg@public.gmane.org
D''oh. Easy answer with sort: $H(MyHash).keys().sort(function(a,b) { return MyHash[a].val - MyHash[b].val; }); --Mike On May 5, 2006, at 11:29 AM, Mike Nosal wrote:> Quick Prototype.js hash question. > > Given: > MyHash = {"Alpha" : {name:"Foo",val:3}, > "Delta" : {name:"Bar",val:2}, > "Beta" : {name:"Baz",val:4} } > > I want to display this set ordered by key - Alpha,Beta,Delta and by > val - 2,3,4 > Prototype.js helps with the hash: > $H(MyHash).keys().sort() will give me Alpha, Beta, Delta > but I''ve not figured out how to extract the keys in sorted order > "Delta,Alpha,Beta" according to val. > > Thoughts?
Apparently Analagous Threads
- http request, hash table
- How to store the same key multi times in a Hash ?
- share an hash ..
- how to pass a hash as a parameter in link_to_remote
- clang error: static_assert failed "Cache the hash code or make functors involved in hash code and bucket index computation default constructible"