The COMPARATOR argument can be an integer, which just
specifies which field you want to be the sort key.
Eg, to sort by second name:
>> sort/compare/reverse db 2
== [
["bob" "Smith" "12"]
["dan" "murphy" "25"]
["mike" "Coogan" "6"]
]
For more complex sorts, you pass your own function,
but to make it a stable sort (doesn't change order
when compared elements are the same), you need to
return one of three values: -1, 0, or 1.
Eg:
sort/compare db func [a b][
case [a/2 > b/2 [1] a/2 < b/2 [-1] true 0]
]
== [
["mike" "Coogan" "6"]
["dan" "murphy" "25"]
["bob" "Smith" "12"]
]
Regards,
Anton.
> How do you sort a block of blocks on an element other than the first?
>
> For example:
>
> db: [
> ["bob" "Smith" "12"]
> ["dan" "murphy" "25"]
> ["mike" "Coogan" "6"]
> ]
>
> How do I sort by last name or by age
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.