Page 1 of 1

Find difference between 2 flds

Posted: Thu May 08, 2014 5:06 am
by Simon
Hello forumer's, (??)
I have seen and this:
http://forums.runrev.com/phpBB2/viewtop ... =7&t=16184
with it's nifty split/combine but now I need the difference between 2 fields
fld 1
Hello
World
Red

fld 2
World
Blue
Hello
Green

Note that there are duplicates but not in the same order and differences.
I think I'd like an output
fld 1 -Blue, -Green
fld 2 -Red
or maybe the other way, doesn't matter
fld 1 Red
fld 2 Blue,Green
I'm sure there is some kind of nifty array method to do this.

Any ideas?

Simon
Edit (Bad Post!)
I have tried using an array but can't get my head around the different order.
I can do this with lineOffset but thought I could learn more about array manipulations for larger datasets.
And yes I'd dump the fields into variables first.

Re: Find difference between 2 flds

Posted: Thu May 08, 2014 9:38 am
by bn
Hi Simon,

here is a way to find unique entries in each of two lists. I uses the "split ... as list" variant of split.
Then it deletes indexes (variables) from the two arrays crosswise to arrive at the unique indexes in each of the arrays.

Code: Select all

on mouseUp
   put field "f1" into tF1
   put field "f2" into tF2
   
   -- split with return as set will use the lines of the list as index
   split tF1 with return as set
   split tF2 with return as set
   
   -- create a copy of the arrays to work on for the result, see below
   put tF1 into tF1Res
   put tF2 into tF2Res
   
   -- delete every index in tF2 that is also in tF1 (= duplicates)
   repeat for each key aKey in tF1
      delete variable tF2Res[aKey]
   end repeat
   
   -- now delete every index in tF1 that is also in tF2 (= duplicates)
   repeat for each key aKey in tF2
      delete variable tF1Res[aKey]
   end repeat
   
   put "unique in field 1 compared to field 2: " & cr &  the keys of tF1Res into field "fRes"
   
   put cr & cr & "unique in field 2 compared to field 1: " & cr & the keys of tF2Res after field "fRes"
   
end mouseUp
Kind regards
Bernd, a forumer :)

Re: Find difference between 2 flds

Posted: Thu May 08, 2014 11:19 am
by [-hh]
..........

Re: Find difference between 2 flds

Posted: Fri May 09, 2014 12:39 am
by Simon
Thank You!

Bernd,
"delete variable tF2Res[aKey]" that is what I was looking for, couldn't get my head around it.

Hermann,
I remember this stack when it was first posted, impressive stuff. I have to improve my filing technique.

Thanks again,
Simon

Re: Find difference between 2 flds

Posted: Fri May 09, 2014 5:00 am
by [-hh]
..........

Re: Find difference between 2 flds

Posted: Fri May 09, 2014 5:18 am
by FourthWorld
[-hh] wrote:Hope you and others will open their archive of posted stacks and helpful snippets, with tags to make them findable.
I think I missed something: is RevOnline not working now?

Re: Find difference between 2 flds

Posted: Fri May 09, 2014 5:31 am
by [-hh]
..........

Re: Find difference between 2 flds

Posted: Fri May 09, 2014 10:11 am
by bn
RevOnline does work very well for me in 6.6.2 RC3.

The problem seems to be that hanging/not working is different for different users and the bug(s) are difficult to reproduce. But I hope it is getting there. I did not try to upload via LC 6.6.2 RC3 yet.
Bug 11387

Kind regards
Bernd