filter?

Dick Kriesel dick.kriesel at mail.com
Thu Jun 23 06:40:30 EDT 2011


On Jun 22, 2011, at 10:58 PM, Pete wrote:

> I may be wrong, but I don't think intersect solves the problem.  If I
> understand the dictionary correctly, this will remove all the t1 keys that
> do NOT match t2 keys so it does the opposite of what is needed.

Thanks, Pete. I misunderstood the OP.

He wants the symmetric difference.
    <http://en.wikipedia.org/wiki/Symmetric_difference>

Here's a way:


function symmetricDifferenceOfLists t1, t2
   split t1 by cr and tab
   split t2 by cr and tab
   return the keys of symmeticDifferenceOfArrays( t1, t2 )
end symmetricDifferenceOfLists 
   
function symmeticDifferenceOfArrays p1, p2
   local tResult
   put differenceOfArrays( p1, p2 ) into tResult
   union tResult with differenceOfArrays( p2, p1 )
   return tResult
end symmeticDifferenceOfArrays

function differenceOfArrays t1, p1
   repeat for each key tKey in p1
      delete variable t1[ tKey ]
   end repeat
   return t1
end differenceOfArrays


In comparison, Jacque's code is looking lean.

-- Dick






More information about the use-livecode mailing list