6 Replies Latest reply on May 26, 2006 4:48 PM by NSurveyor

    Array sortOn

    Level 7
      Hi there,

      Can any one tell me if it is possible to sort an array Numeric but in
      Descending order?

      // Array.NUMERIC deals with values as Numbers at not strings. But by default
      sorts in Ascending
      sortOn ("pos",Array.NUMERIC);

      Thanks in advanced


        • 1. Re: Array sortOn
          NSurveyor Level 2
          Of course! Look up sortOn in the Help panel... in fact they show how to sort descending sorted numerically:

          my_array.sortOn(someFieldName, Array.DESCENDING | Array.NUMERIC);

          So in your case, you would simply stick in "pos" for someFieldName, and whatever your array is for my_array.
          • 2. Re: Array sortOn
            Level 7
            Of course, duh. I'm ashamed of myself.

            Thanks allot...


            "NSurveyor" <> wrote in message ...
            > Of course! Look up sortOn in the Help panel... in fact they show how to
            > sort
            > descending sorted numerically:
            >
            > my_array.sortOn(someFieldName, Array.DESCENDING | Array.NUMERIC);
            >
            > So in your case, you would simply stick in "pos" for someFieldName, and
            > whatever your array is for my_array.
            >


            • 3. Re: Array sortOn
              NSurveyor Level 2
              You're welcome.
              • 4. Re: Array sortOn
                Level 7
                Sorry, mean while I have another question...




                I have this array with 3 elements. For each element I have 3 objects:

                Flash 7, As2




                // Declare the array
                var myArray:Array = new Array ();


                // Push the elements
                myArray.push ({ name:"Regina", win:10, loose:800 });
                myArray.push ({ name:"Ana", win:30, loose:500 });
                myArray.push ({ name:"John", win:10, loose:100 });




                // Sort by loose
                // Outputs John / Ana / Regina /


                myArray.sortOn ("loose");
                trace (myArray[0].name + " / " + myArray[1].name + " / " +
                myArray[2].name + " / ");




                // Sort by win
                // Outputs Ana / Regina / John /


                myArray.sortOn ("win", Array.DESCENDING | Array.NUMERIC);
                trace (myArray[0].name + " / " + myArray[1].name + " / " +
                myArray[2].name + " / ");

                What I would like is to have on the final sort is:



                // Ana / John / Regina /



                Do you have any idea in how to achieve this?



                Thanks





                "NSurveyor" <> wrote in message ...

                � You're welcome.


                • 5. Re: Array sortOn
                  NSurveyor Level 2
                  I'm a bit confused on what you want. How do you want the array sorted?
                  • 6. Re: Array sortOn
                    NSurveyor Level 2
                    You want primary sort win descending, and secondary sort loose descending as well?