inverse of intersect array with templateArray

Monte Goulding monte at sweattechnologies.com
Sat Mar 23 21:44:40 EDT 2013


On 24/03/2013, at 12:37 PM, Dick Kriesel <dick.kriesel at mail.com> wrote:

>> It needs more testing before I share it.  How soon do you need it, Monte?
> 
> Detecting changes from one multidimensional array to another now passes my tests, as confirmed by applying the derived changes to the original data, and getting matching results.
> 
> Are you still interested?  Do you want the code in a posting to the list, or in a stack sent off-list?

Hi Dick

I'm still interested. I had my own crack at it with this although I haven't setup a test case for it:

command ArrayDiff @pArray1, at pArray2
   local tKeys1,tKeys2
   -- use the list of keys so we make sure we support empty elements
   put the keys of pArray1 into tKeys1
   put the keys of pArray2 into tKeys2
   -- any keys in pArray1 that aren't in pArray2 should stay
   repeat for each line tKey in tKeys2
      -- any keys in pArray2 that aren't in pArray1 should stay
      if tKey is among the lines of tKeys1 then
         if pArray2[tKey] = pArray1[tKey] then
            delete variable pArray2[tKey]
            delete variable pArray1[tKey]
         end if
         -- if they are different and only one is an array then keep both
         if pArray1[tKey] is an array and pArray2[tKey] is an array then
            ArrayDiff pArray1[tKey],pArray2[tKey]
         end if
      end if
   end repeat
end ArrayDiff

Cheers

--
Monte Goulding

M E R Goulding - software development services
mergExt - There's an external for that!








More information about the use-livecode mailing list