Re: minimum function?
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