#456 Add a comparator for sorting numeric array items.

v4.2.0
closed
Rick McGuire
Classes (154)
complete
5
2014-08-14
2012-06-08
Rick McGuire
No

The compareTo method of the String class performs a string order comparison and the various string comparators are also string compares. Sorting data as numeric items is a fairly comment thing, so a simple comparator such as this should be part of the standard comparator set:

-- a custom comparator that sorts strings as numeric values rather than
-- strings
::class numberComparator subclass comparator
::method compare
use strict arg left, right
-- perform the comparison on the names. By subtracting
-- the two and returning the sign, we give the expected
-- results for the compares
return (left - right)~sign

Discussion

  • Rick McGuire
    Rick McGuire
    2013-11-20

    • Pending work items: --> none
    • Milestone: None --> v4.2.0
     
  • Rick McGuire
    Rick McGuire
    2013-11-22

    • status: open --> accepted
    • assigned_to: Rick McGuire
    • Pending work items: none --> code+doc+test
     
  • Rick McGuire
    Rick McGuire
    2013-11-22

    • Pending work items: code+doc+test --> doc
     
  • Rick McGuire
    Rick McGuire
    2013-11-25

    • status: accepted --> pending
    • Pending work items: doc --> complete
     
  • Rick McGuire
    Rick McGuire
    2013-11-25

    Docs commit [r9562]

     

    Related

    Commit: [r9562]

  • Rick McGuire
    Rick McGuire
    2014-04-15

    • status: pending --> closed
     


Anonymous


Cancel   Add attachments