2 Replies Latest reply on Sep 13, 2006 9:40 AM by scsherwood

    Array.sortOn()

    scsherwood
      I have a private function in a class file in which I want to sort an array called "numbers". The array has 5 elements each of which are objects with the fields "n" and "h". When I try to use the sortOn("n", Array.NUMERIC), the option field is completely ignored. The array is sorted but using the default method where numbers are sorted as strings.

      Does anyone know why OPTION field of "sortOn" is ignored inside a class function?

        • 1. Re: Array.sortOn()
          scsherwood Level 1
          After further investigation it turns out if the Array is created inside of the class, which mine is, the option field of 'sortOn' is completely ignored. If the Array is created outside of the class and passed to the method inside the class, then the option field, 'Array.NUMERIC' is read and the sort is done numerically.

          So, there is something about an Array created inside a class that causes the static property, 'Array.NUMERIC', on the Array Class to disappear.

          Anybody got any ideas?
          • 2. Re: Array.sortOn()
            scsherwood Level 1
            Stupidity reigns. I solved the problem myself. I was chasing my tail. The array that was being sorted, even though it looked like numbers, was actually an array of strings. Once I forced the elements to numbers, everything worked perfectly. DUH! I hate it when I can't see that 2 + 2 doesn't equal 5 no matter how long I stare at it.