At 5:59 PM +1200 7/11/04, Sean Wilson wrote:
While Irv has already provided some crafty code, it's worth noting that for performance's sake you only need to iterate through the _smaller_ list looking for duplicates.
-Sean.
Sean is right. Here's a revised version that accounts for this (still untested):
on FindMatches listA, listB -- The output will be a list of all items which are in both lists matchList = [] nItemsInListA = count(listA) nItemsInListB = count(listB)
if nItemsInListA < nItemsInListB then
-- iterate through all the items in the first list
repeat with i = 1 to nItemsInListA
-- grab each item
itemFromListA = listA[i]
-- see if it exists in the other list
where = getOne(listB, itemFromListA)
-- if so, add it to the resulting matching list
if where > 0 then
append(matchList, itemFromListA)
end if
end repeat else
-- iterate through all the items in the second list
repeat with i = 1 to nItemsInListB
-- grab each item
itemFromListB = listB[i]
-- see if it exists in the other list
where = getOne(listA, itemFromListB)
-- if so, add it to the resulting matching list
if where > 0 then
append(matchList, itemFromListB)
end if
end repeatend if -- return the matching list return matchList end
--
Multimedia Wrangler.
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
