Sort items in a list without OSAXen
Sort items in a list without OSAXen
- Subject: Sort items in a list without OSAXen
- From: "Joseph A. Weaks" <email@hidden>
- Date: Sat, 1 Sep 2001 23:54:28 -0500
ASers,
I have a variable that contains random numbers in a list, say
{1,2,3,4}, and I need the sum of the highest three.
I don't want to use an OSAX 'sort' command for portability reasons.
My approach has been to first sort the list in descending in order
which lets me get the sum items 1-3. Here's my solution so far...
-- Sorts a list in descending order
property HighNumber : 10 -- Highest possible number
property SortedList : {} as list
SortList({9, 1, 3, 4, 10, 6, 5, 7, 2, 1, 1})
on SortList(UnsortedList)
repeat with EachNumber from HighNumber to 1 by -1
repeat with x from 1 to number of UnsortedList
if item x of UnsortedList is EachNumber then
set SortedList to SortedList & item x
of UnsortedList as list
end if
end repeat
end repeat
return SortedList
end SortList
Any more economical way?
Joe Weaks
--
* * * * * * * * * * * * * * * * * * * * *
Joe Weaks
A Bible, Greek, Mac, and Scripting Nut
* * * * * * * * * * * * * * * * * * * * *