inverse of intersect array with templateArray

Dick Kriesel dick.kriesel at mail.com
Sat Mar 23 03:41:19 EDT 2013


On Mar 23, 2013, at 12:13 AM, Monte Goulding <monte at sweattechnologies.com> wrote:

> Hi Folks
> 
> Just checking if there isn't an undocumented inverse of the intersect command? What I need is a function that can take two multi-dimensional arrays and return only keys and elements that both don't have in common.. I'm guessing I need to implement this myself as a recursive function but just want to make sure before I go ahead seeing as intersect seems to do the exact opposite of what I want...



Hi, Monte.  I think what you're looking for is called the "symmetric difference."
   <http://en.wikipedia.org/wiki/Symmetric_difference>

Here's a way to do that in LC.  It's simplified from a library I use.

function symmetricDifferenceFromArrays pArray1, pArray2
   local tArray1, tArray2
   put differenceFromArrays( pArray1, pArray2 ) into tArray1
   put differenceFromArrays( pArray2, pArray1 ) into tArray2
   union tArray1 with tArray2
   return tArray1
end symmetricDifferenceFromArrays

function differenceFromArrays tArray1, @pArray2
   repeat for each key tKey in pArray2
      delete variable tArray1[ tKey ]
   end repeat
   return tArray1
end set_differenceFromArrays

Does that work for you?

-- Dick



More information about the use-livecode mailing list