• 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: Position of an element in a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Position of an element in a list


  • Subject: Re: Position of an element in a list
  • From: "Nigel Garvey" <email@hidden>
  • Date: Thu, 3 Aug 2017 10:13:31 +0100

Shane Stanley wrote on Thu, 3 Aug 2017 09:35:27 +1000:

>On 3 Aug 2017, at 8:45 am, Nigel Garvey <email@hidden> wrote:
>>
>> the version here seems a bit perverse
>
>But in a very attractive way :-)

Thank you.  :)

>It could be good for long lists

But a vanilla repeat still seems to be faster (assuming all-vanilla
values):

  on indexOf:aValue inList:theList withCaseInsensitivity:caseInsensitive
    script o
      property l : theList

      on search()
        repeat with i from 1 to (count theList)
          if (item i of my l is aValue) then return i
        end repeat

        return 0
      end search
    end script

    if (caseInsensitive) then
      ignoring case
        return o's search()
      end ignoring
    else
      considering case
        return o's search()
      end considering
    end if
  end indexOf:inList:withCaseInsensitivity:

  set theList to {5, 2, 6, 9, 4, current date, "TTT", 6, "TT", 3, weekday of
(current date)}
  set searchList to {}
  repeat 4999 times
    set end of my searchList to some item of theList
  end repeat
  set end of my searchList to "T"

  -- Get the index of the 5000th item to see how long it takes.
  its indexOf:"t" inList:searchList withCaseInsensitivity:true


NG

 _______________________________________________
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: Position of an element in a list
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Do Shell Script returns empty string but works in Terminal
  • Next by Date: Re: Position of an element in a list
  • Previous by thread: Re: Position of an element in a list
  • Next by thread: Re: Position of an element in a list
  • Index(es):
    • Date
    • Thread