• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sort items in a list without OSAXen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
* * * * * * * * * * * * * * * * * * * * *


  • Follow-Ups:
    • Re: Sort items in a list without OSAXen
      • From: Timothy Bates <email@hidden>
  • Prev by Date: TIDs ahoy (was Re: coercing a list)
  • Next by Date: Re: Sort items in a list without OSAXen
  • Previous by thread: Re: TIDs ahoy (was Re: coercing a list)
  • Next by thread: Re: Sort items in a list without OSAXen
  • Index(es):
    • Date
    • Thread