How can you sort a list of numbers using AppleScriptObjC without making the list unique?
TIA.
-Chris
----------------------------------------------------------------
use AppleScript version "2.4" -- 10.10 or later
use framework "Foundation"
use scripting additions
set theList to {2, 20, 3, 1, 21, 21}
-- Make unique set
tell current application's NSSet to set theSet to setWithArray_(theList)
-- Define sorting
tell current application's NSSortDescriptor to set theDescriptor to sortDescriptorWithKey_ascending_(missing value, true)
-- Sort
set sortedList to (theSet's sortedArrayUsingDescriptors:{theDescriptor}) as list
return sortedList
----------------------------------------------------------------
Make an array rather than a set. You also don’t need a sort descriptor for a basic sort:
use AppleScript version "2.4" -- 10.10 or later
use framework "Foundation"
use scripting additions
set theList to {2, 20, 3, 1, 21, 21}
set theArray to current application's NSArray's arrayWithArray:theList
set sortedList to (theArray's sortedArrayUsingSelector:"compare:") as list
return sortedList