Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#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-22

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

    • status: accepted --> pending
    • Pending work items: doc --> complete
     


Anonymous


Cancel   Add attachments