On May 9, 3:40 am, kstubs <[email protected]> wrote: > How do you sort descending? Also, how do you distinguish between Alpha, > Alpha-numeric, and Numeric sorts? > > Thanks, loving the methods like sort() and uniq() off enumerable? > > Karl..
`Enumerable` doesn't have a `sort` function. `Array` does, it's part of JavaScript; `Enumerable` has `sortBy` which is similar. (One big difference is that `Array#sort` processes the array in-place; `Enumerable#sortBy` *returns* a new array of the elements in the desired order, leaving the original `Enumerable` unchanged.) In both cases (`Enumerable#sortBy` and `Array#sort`), you can pass in a function that will get called to compare two elements during the sorting process. The function should return less than zero if the first argument is "less than" the second (e.g., should be before it in your sort order), zero if they're the same, or greater than zero if the first is "greater than" the second (should be after it). That means you're entirely in control of how the elements are sorted. Doing a reverse sort, or dealing with numeric vs. alpha, is entirely down to how you write the function that you pass into the `sort` / `sortBy` function. MDC has some examples of `Array#sort` that may be useful: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort HTH, -- 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 [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.
