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, 08 Feb 2011 08:39:09 +0900
- From: "Stephen J. Turnbull" <turnbull@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>
Josh Glover writes: > On 7 February 2011 09:55, Raymond Wan <rwan.kyoto@example.com> wrote: > > > Perhaps languages like Perl and Python can [sort arbitrary lists of objects] > > Sure. Here's how to sort arrays of hashes in Perl and Ruby: > > Perl: > > @array = sort { $a{some_key} <=> $b{some_key} } @array; > > Ruby: > > array.sort! {|a, b| a['some_key'] <=> b['some_key'] } Something similar works in other languages, too (ie, all the languages I know including BrainF!ck -- of course in that last you have to implement your own hash tables ;-), but Dave's requirement is different. He doesn't want to sort an array on the value associated with a specified key in each element of the array, where each such element happens to be a hash containing that key. 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. Of the languages so far mentioned, I would consider Perl most likely to provide such a facility (but I bet it doesn't). OTOH, there are language like SNOBOL (and I believe Tcl) where "everything *is* a string" (unlike Perl, which decides the type of an object in a context-dependent way). Then I would suppose that Dave's requirement makes sense.
- Follow-Ups:
- Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- From: Josh Glover
- 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
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Importing WiFi equipment
- Next by Date: Re: [tlug] Importing WiFi equipment
- Previous by thread: Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- Next by thread: Re: [tlug] [Javascript] Shouldn't there be a sort option on objects
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links