valueDiff for arrays?

Brian Milby brian at milby7.com
Fri Aug 3 19:26:35 EDT 2018


"symmetric difference" will get you the first part (unique keys)

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

On Fri, Aug 3, 2018 at 5:54 PM, Mark Wieder via use-livecode <
use-livecode at lists.runrev.com> wrote:

> On 08/03/2018 10:40 AM, Richard Gaskin via use-livecode wrote:
>
>> We have a command for obtaining the difference between arrays, where
>> "difference" is defined as having different keys.
>>
>> What I could use at the moment is a means of obtaining an array which is
>> the difference is both keys present in one but not in the other, and values
>> that are different for those elements where they keys are present in both.
>>
>
> Considering how easy the first part is to code, I doubt a feature request
> would get a second glance.
>
> function arrayDifferences pArray1, pArray2
>    local tDiff1, tDiff2, tDiffs
>
>    difference pArray1 with pArray2 into tDiff1
>    difference pArray2 with pArray1 into tDiff2
>    union tDiff1 with tDiff2 into tDiffs
>    return tDiffs
> end arrayDifferences
>
> For the second part, I'm not sure what the output would look like... do
> you want an array with duplicate keys? A multidimensional array with the
> same keys in each but different values? What's the use case?
>
> --
>  Mark Wieder
>  ahsoftware at gmail.com
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list