Re: Position of an element in a list
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