Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- Date: Tue, 8 Feb 2011 10:22:55 +0100
- From: Josh Glover <jmglov@example.com>
- Subject: Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- References: <4D4E75AB.5060703@example.com> <4D4FB368.4010403@example.com> <AANLkTimk8AUJMRiwbPjGfDfciCwfaQr9_o3vBXtW2+rW@example.com> <87lj1rza76.fsf@example.com>
On 8 February 2011 00:39, Stephen J. Turnbull <turnbull@example.com> wrote: > He wants to reorder the > keys of the hash so that mapping over the hash in its "natural" order > of keys produces the values in the desired order. The easiest way to do that (in Ruby--Perl syntax is basically the same, Javascript syntax shouldn't be too different) is simply: my_object.keys.sort{|a,b| a[:some_key] <=> b[:some_key]}.map {...} > Of the languages so far mentioned, I would consider Perl most likely > to provide such a facility (but I bet it doesn't). Ruby has a hash that keeps the keys FIFO ordered, if that makes sense. The first key you put in is the first key that GoogleOnlyKnowsTheNameOfTheHashClass#keys will return. -- Cheers, Josh
- Follow-Ups:
- [tlug] Are ordered hashes useful?
- From: Stephen J. Turnbull
- References:
- [tlug] [Javascript] Shouldn't there be a sort option on objects
- From: Dave M G
- Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- From: Raymond Wan
- Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- From: Josh Glover
- Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- From: Stephen J. Turnbull
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] [announcement] 2011-02-19 Technical meeting.
- Next by Date: Re: [tlug] Great Git resources
- Previous by thread: Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- Next by thread: [tlug] Are ordered hashes useful?
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links