Sort using a custom comparator: Difference between revisions

m
m (→‎{{header|AppleScript}}: Another typo. :\)
Line 390:
While vanilla AppleScript doesn't have sort facilities of its own, a customisable sort written in vanilla, such as [https://macscripter.net/viewtopic.php?pid=194430#p194430 this one on MacScripter], can be fed user-defined comparison handlers to do practically any kind of sorting. The following assumes that the customisable sort just mentioned has been compiled and saved in a suitable "Script Libraries" folder as "Custom Iterative Ternary Merge Sort.scpt":
 
<lang applescript>use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
use sorter : script "Custom Iterative Ternary Merge Sort"
 
set listOfText to words of "now is the time for all good men to come to the aid of the party"
 
script descendingByLengthThenAscendingLexicographically
script descendingByLengthThenDescendingLexicographically
on isGreater(a, b)
set lenA to (count a)
Line 408:
 
-- Sort the whole list using the above customiser.
tell sorter to sort(listOfText, 1, -1, {comparer:descendingByLengthThenDescendingLexicographicallydescendingByLengthThenAscendingLexicographically})
return listOfText</lang>
 
557

edits