valueDiff for arrays?

Mark Wieder ahsoftware at sonic.net
Fri Aug 3 19:54:17 EDT 2018


On 08/03/2018 04:26 PM, Brian Milby via use-livecode wrote:
> "symmetric difference" will get you the first part (unique keys)

Nice. One-stop shopping.

> 
> You could shorten the compare loop by using "intersect" (to get common keys)
> 
> 
> function getKeys pLeft, pRight
>     local tIntersect, tResult
> 
>     intersect pLeft with pRight into tIntersect
>     repeat for each key tKey in tIntersect
>        if pLeft[tKey] is not pRight[tKey] then
>           delete variable pRight[tKey]
>        end if
>     end repeat
> 
>     symmetric difference pLeft with pRight into tResult
>     return the keys of tResult
> end getKeys

I think Richard was aiming for (if I can put words in his mouth here) 
the set of just the elements with duplicate keys but different values. 
Here's my take on that, returning an array with two subarrays:

function getKeys pLeft, pRight
    local tIntersect, tResult

    intersect pLeft with pRight into tIntersect
    repeat for each key tKey in tIntersect
       if pLeft[tKey] is pRight[tKey] then
          delete variable pRight[tKey]
       end if
    end repeat
    put tIntersect into tResult["left"]
    intersect pRight with tIntersect into tResult["right"]
    return tResult
end getKeys


-- 
  Mark Wieder
  ahsoftware at gmail.com




More information about the use-livecode mailing list