• 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
Re: minimum function?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: minimum function?


  • Subject: Re: minimum function?
  • From: Martin Orpen <email@hidden>
  • Date: Wed, 06 Apr 2005 08:44:23 +0100

on 6/4/05 03:10, kai at email@hidden wrote:

> on min(l)
> set m to l's item 1
> repeat with i in rest of l
> if i < m then set m to i
> end repeat
> m's contents
> end min
>
> min({27, 9, 3, 19, 5, 8})


Thanks for the ultra-informative post :-)

I'd just like to add, for the record, that AS is not fast enough to do this
sort of task if you are dealing with large lists.

The shell will deliver in less than one second what the cleanest AS script
will take at least 20 seconds to do:


set nList to {}
repeat 1000 times
    set end of nList to random number from 1 to 99999
end repeat

sortMin(nList)

on sortMin(nList)
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ASCII character 10
    set sList to nList as string
    set n to do shell script "echo " & quoted form of sList & " | sort -n"
    set AppleScript's text item delimiters to oldDelims
    set x to paragraph 1 of n
    return x
end sortMin


Using *sort* means that you aren't restricted to sorting numbers. It can
also be scaled to work with massive lists by writing/reading to disk.

Regards

--
Martin Orpen


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: minimum function?
      • From: jj <email@hidden>
References: 
 >Re: minimum function? (From: kai <email@hidden>)

  • Prev by Date: Re: Merge PDFs
  • Next by Date: Re: matching strings with accented characters
  • Previous by thread: Re: minimum function?
  • Next by thread: Re: minimum function?
  • Index(es):
    • Date
    • Thread