If the sorted order of the hash keys isn't what you want, you might also
consider assigning ordinals as part of the hash key.  Assuming you have less
than 10000 hash keys, I would do something like NNNN_myKey as a key, where
NNNN is a number that you increase each time you put an item into the hash.
 Of course, if you are using a hash as a means of ensuring that an item is
never collected more than once, you will need ANOTHER hash that maps myKey
to NNNN so you can test to see if you have already seen myKey.

On Wed, Oct 5, 2011 at 5:47 AM, T.J. Crowder <t...@crowdersoftware.com> wrote:

> On Oct 4, 5:38 pm, surge <gera...@gmail.com> wrote:
> > I have this nasty problem with hashes. IE 8 disregards the order of
> > hash element declarations and when I do hash_name.each(), the result
> > is "out of order" so to speak -- although I know that the order is not
> > guaranteed. What's the best solution if I want to stay with hashes?
>
> You said it yourself: The order is not guaranteed. It could change
> from one dot release of the browser to the next. If you need a
> specific order, you need to get the keys (Hash#keys[1]) and sort them
> (Array#sort[2]), then loop through them in their (now) sorted order.
>
> [1] http://api.prototypejs.org/language/Hash/prototype/keys/
> [2] http://es5.github.com/#x15.4.4.11
> --
> T.J. Crowder
> Independent Software Engineer
> tj / crowder software / com
> www / crowder software / com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to
> prototype-scriptaculous@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>


-- 
Shane McCarron
halindr...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to