filter command

Dave Cragg dcragg at lacscentre.co.uk
Wed Apr 10 12:38:02 EDT 2002


At 4:53 pm +0100 10/4/02, Dave Cragg wrote:

>function commonLines pList1, pList2
>   repeat for each line tLine in pList1
>     put 1 into tArray[tLine]
>   end repeat
>   repeat for each line tLine in pList2
>     add 1 to tArray[tLine]
>   end repeat
>   put keys(tArray) into tKeys
>   repeat for each line tKey in tKeys
>     if tArray[tKey] > 1 then
>       put tKey & cr after tRetVal
>     end if
>   end repeat
>   delete char -1 of tRetVal
>   return tRetVal
>end commonLines

I wasn't thinking too hard. The above works if the lines in each list 
are unique, but not if there may be duplicate lines.

This is better, I think.

function commonLines pList1, pList2
   repeat for each line tLine in pList1
     put 1 into tArray[tLine]
   end repeat
   repeat for each line tLine in pList2
     if tArray[tLine] = 1 then
       put 2 into tArray[tLine]
       put tLine & cr after tRetVal
     end if
   end repeat
   delete char -1 of tRetVal
   return tRetVal
end commonLines



More information about the use-livecode mailing list