• 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: Getting the maximum value and minimal values in a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the maximum value and minimal values in a list


  • Subject: Re: Getting the maximum value and minimal values in a list
  • From: KOENIG Yvan <email@hidden>
  • Date: Tue, 14 Sep 2010 10:48:24 +0200


Two issues with this, Yvan. 1) The labels 'minimum' and 'maximum' are
used by the Satimage OSAX and so the script errors for me. 2) If all the
values in the list are less than zero, the maximum returned is 0. Here's
a slight modification which seems to work better:

 set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, 3000, 4}

 set min to beginning of list_of_values
 set max to min
 repeat with i from 2 to (count list_of_values)
   set the_value to item i of list_of_values
   if (the_value > max) then
     set max to the_value
   else if (the_value < min) then
     set min to the_value
   end if
 end repeat

 {min, max}

Thanks

(1) I missed the fact that Satimage use minimum and maximum

(2) Yt was late yesterdays when I took care that I forgot the case of negative values so I modified the code.
This morning I edited the variables names and here it is :

set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, -20, 3000, 4}

set min to first item of list_of_values
set max to min
repeat with ref_to_value in list_of_values
set the_value to contents of ref_to_value
if the_value > max then
set max to the_value
else if the_value < min then
set min to the_value
end if
end repeat

{min, max}

As you see, when I may do that, I don't use index in loops.

Yvan KOENIG (VALLAURIS, France) mardi 14 septembre 2010 10:48:04


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting the maximum value and minimal values in a list
      • From: Alex Zavatone <email@hidden>
References: 
 >Re: Getting the maximum value and minimal values in a list (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: Applescript: force garbage collection? (NSAppleScript call from Cocoa app)
  • Next by Date: Getting into Adobe Reader
  • Previous by thread: Re: Getting the maximum value and minimal values in a list
  • Next by thread: Re: Getting the maximum value and minimal values in a list
  • Index(es):
    • Date
    • Thread