Nested array comparisons

David Beck david at rotundasoftware.com
Sat Mar 23 21:40:04 CDT 2013


Here is a function, in the mean time, that will do a deep comparison of arrays:

function arraysAreEqual array1, array2
   if array1 is not array2 then return false
   put the keys of array1 into theKeys
   repeat for each line thisKey in theKeys
      put 0 into numberOfArrays
      if array1[ thisKey ] is an array then add 1 to numberOfArrays
      if array2[ thisKey ] is an array then add 1 to numberOfArrays
      if numberOfArrays is 1 then return false
      if numberOfArrays is 2 then
         if not arraysAreEqual( array1[ thisKey ], array2[ thisKey ] ) then return false
      end if
   end repeat
   
   return true
end arraysAreEqual

On Mar 23, 2013, at 12:43 PM, David Beck <david at rotundasoftware.com> wrote:

> 
> If one has two nested arrays, can you compare the two for equality by doing
> 
> if deepArray_1 is deepArray_2 then
>   -- do whatever
> end if
> 
> It looks like this does not work. That is, you get false positives at times when the two arrays are in fact not equal. Can not find documentation to determine whether this is bug of the expected behavior!
> 
> David Beck




More information about the use-livecode mailing list