Finding non-common elements in two arrays

Buster wouter.abraham at scarlet.be
Sun Nov 6 05:51:36 EST 2005


On 06 Nov 2005, at 01:39, Alex Tweedly wrote:

> Bruce A. Pokras wrote:
>
>> The intersect function will return the common elements of two  
>> arrays. Is there any array methodology that will return the non- 
>> common elements of two arrays? I download a government list each  
>> month, and I would like an easy way to spot the records that are  
>> either new or changed. Currently, I use a repeat structure to go  
>> through the old list line-by-line to see if any lines are not  
>> identically found in the new list (using offset), and collect a  
>> third list of any lines in which offset=0. After splitting the old  
>> and new lists into arrays, an "inverse-intersect" function or  
>> equivalent would seem to be a more elegant way of doing this.
>>
>> Any ideas?
>
> It's a bit of a faff, so it's arguably not elegant at all, and  
> you'd need to do some testing to see if it's faster or not.
> (Oh - and the final result still needs cleaning up ....)
>
>> on mouseUp
>>         put fld "F1" into t1
>>     repeat for each line L in t1
>>         put L & TAB & "1" & cr after tA1
>>     end repeat
>>     split tA1 by CR and TAB
>>          put fld "F2" into t1
>>     repeat for each line L in t1
>>         put L & TAB & "2" & cr after tA2
>>     end repeat
>>     split tA2 by CR and TAB
>>         union tA1 with tA2
>>     combine tA1 with CR and TAB
>>       filter tA1 with ("*"&TAB&"2")
>>       put tA1 into fld F3
>>      end mouseUp
>>
>
> -- 
> Alex Tweedly       http://www.tweedly.net

Hi,
This method is reporting the missing lines of field 1 in field 2 and  
not the unique lines in both.
This does:

on mouseUp
   put fld 2 into f2
   repeat for each line i in fld 1
     get lineoffset(i,f2)
     if it = 0 then put i & cr after tList
     else delete line it of f2
   end repeat
   put tList & f2 into fld 3
end mouseUp

Greetings,
Wouter






More information about the use-livecode mailing list