[REBOL] Re: Sort by first part of line
From: greggirwin:mindspring at: 3-Sep-2002 16:18
Hi Louis,
<< I still don't quite understand sort. How do I sort the following lines
by
the numbers only (not by the letters and not by the length). Note that
there is a space before each number in the test data below. >>
How about this? (assuming items are space delimited strings)
compare-items: func [a b /local aa bb] [
aa: to integer! first parse a none
bb: to integer! first parse b none
either aa = bb [0][either aa < bb [-1][1]]
]
sort/compare data :compare-items
Not terribly efficient, as it's doing a lot of work on each comparison, but
it's a start.
--Gregg