Sort an integer array: Difference between revisions

Shorter code using ooRexx-provided sorting
(jq)
(Shorter code using ooRexx-provided sorting)
Line 998:
=={{header|ooRexx}}==
<lang rexx>a = .array~of(4, 1, 6, -2, 99, -12)
a~sortWith(.numbercomparator~new)
say "The sorted numbers are"
say a~sortWith(.numericComparator~new)~makeString</lang>
do num over a
say num
end
 
-- 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</lang>
Output:
<pre>
Anonymous user