Finding non-common elements in two arrays

Alex Tweedly alex at tweedly.net
Sun Nov 6 08:49:46 EST 2005


Buster wrote:

>
> On 06 Nov 2005, at 01:39, Alex Tweedly wrote:
> Hi,
> This method is reporting the missing lines of field 1 in field 2 and  
> not the unique lines in both.

That's right - that's how I interpreted the original request. It said 
"... spot the records that are either new or changed". It didn't say "or 
deleted".  Wanting both is probably a more reasonable interpretation. 
The second version I sent last night does produce both results, though I 
commented out the  part that I thought wasn't needed.

> 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

Nice clean simple code, but a bit slow.
The "loop" version I sent in my later mail is a bit faster, esp. on 
larger data sets, but unless that's a big problem, I personally would 
stick to this simple code.

Even if Rev does the enhancement Ken requested in BZ, it still won't 
provide a clean way to solve this problem (because it operates on the 
keys of the array, so you need to do the ugly append to each line then 
split ....)

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005




More information about the use-livecode mailing list