[Rails-spinoffs] Sorting a hash
Mike Nosal
mnosal at mitre.org
Fri May 5 17:19:55 GMT 2006
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?
More information about the Rails-spinoffs
mailing list