Hi,

Sorry, I gave you a bum steer there. `sortBy` works completely
differently from `sort`. Apparently, you only get given one element
(and its index, as a second parameter the documentation doesn't
mention, perhaps it's not explicitly supported) and you're meant to
return some piece of information that will later be used to sort the
result. (`sortBy` builds up an array of the criteria you provide, and
then does a `sort` on it.) You have no control over the order, it will
always be "ascending". So if you were sorting by something numeric,
you could play games with the sign of the values you return or
something, but you're out of luck if you're sorting based on strings
or the like. Instead, just create your own temporary array (perhaps
via `map`) and sort it.

Sorry for the bum steer.
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com


On May 9, 8:46 am, kstubs <[email protected]> wrote:
> Thanks for the tips.  Since my posting I discovered sortBy().  So I'm close,
> but don't see how/where to pass in the 2nd argument to compare.  I have:
>
> list = list.sortBy(function(s) {
>                 if(field.field.startsWith('EventScore') || field.field ==
> 'AAScore')
>                     return Number(Object.values(s)[index]);
>                 else                
>                     return Object.values(s)[index];
>             });
>
> Reason for the if/else is pretty straightforward; this fields beginning with
> EventScore or AAScore are numeric.  Anyhow, how does the 2nd argument work?
>  The above works perfectly, but strictly ascending.
>
> Karl..

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to