• 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: Lowest value of list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lowest value of list


  • Subject: Re: Lowest value of list
  • From: Andrew Oliver <email@hidden>
  • Date: Wed, 14 May 2003 13:36:13 -0700

On 5/14/03 1:03 PM, "Steve Suranie" <email@hidden> wrote:

> Hi all:
>
> I have a list which will vary in number of items which themselves will be
> numbers {"80565432", "56420123", "76492914", 53020442"} - is there a way to
> determine which item in the list has the lowest numerical value?
>

Sure. Iterate through the list keeping track of the lowest number found:

set theList to {"80565432", "56420123", "76492914", "53020442"}

set minVal to (item 1 of theList) as number -- start with the first item
set listCount to number of items in theList -- how big is the list?
repeat with counter from 2 to listCount
if (item counter of theList) as number < minVal then
set minVal to (item counter of theList) as number
end if
end repeat
return minVal


Note that I've added coercion to numbers since the list you provided
actually contained strings, and as strings "50000000000" is actually lower
than "60". If you KNOW the list contains numbers then you can omit the "as
number" elements. On the other hand, if one of the list values can not be
coerced to a number ({"12345", "hello world", "67890"}) the script will
generate an error.

While the loop might seem cumbersome, you should find it's pretty quick.

Finally, it's not clear from your question if you want the lowest value in
the list, or the *index* of the item with the lowest value. If the latter,
change the script to record the index as you loop through the list rather
than the value of the items.

Andrew
:)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Lowest value of list
  • Next by Date: Re: Order of operations (was: Eigenvalues &/or eigenvectors,
  • Previous by thread: Re: Lowest value of list
  • Next by thread: Re: Lowest value of list
  • Index(es):
    • Date
    • Thread