{"ScriptPreparationCode":null,"TestCases":[{"Name":"equality by gettingDifferences","Code":"const equalArrays = (arr1, arr2) =\u003E arr1.length === arr2.length \u0026\u0026\r\narr1.every((element, index) =\u003E getDifferences(element, arr2[index]) === undefined)\r\n\r\nfunction getDifferences(original, modified) {\r\n if (original instanceof Array \u0026\u0026 modified instanceof Array) {\r\n return equalArrays(original, modified)\r\n ? undefined\r\n : modified\r\n }\r\n if (original instanceof Object \u0026\u0026 modified instanceof Object) {\r\n let result = {}\r\n for (const key of Object.keys(modified)) {\r\n const diff = getDifferences(original[key], modified[key])\r\n if (diff !== undefined) {\r\n result[key] = diff\r\n }\r\n }\r\n return !Object.keys(result).length\r\n ? undefined\r\n : result\r\n }\r\n return original === modified\r\n ? undefined\r\n : modified\r\n}\r\n\r\nconst objA = {\r\n a: 1,\r\n b: 2,\r\n c: {\r\n d: 3,\r\n e: [4, {\r\n h: 5\r\n }]\r\n },\r\n f: [6, 7],\r\n g: 8\r\n}\r\nconst objB = {\r\n a: 1,\r\n b: 2,\r\n c: {\r\n d: 3,\r\n e: [4, {\r\n h: 4\r\n }] // field h changed\r\n },\r\n f: [6, 7],\r\n g: 8\r\n}\r\nconst arrA = [objA, objB]\r\nconst arrB = [objA, objA]\r\n\r\nconsole.log(equalArrays(arrA, arrA))\r\nconsole.log(equalArrays(arrA, arrB))","IsDeferred":false},{"Name":"equality by recursion","Code":"const deepEqual = (thing1, thing2) =\u003E {\r\n if (thing1 instanceof Object \u0026\u0026 thing2 instanceof Object)\r\n \treturn Object.keys(thing1).every(key =\u003E deepEqual(thing1[key], thing2[key]))\r\n return thing1 === thing2\r\n}\r\n\r\nconst objA = {\r\n a: 1,\r\n b: 2,\r\n c: {\r\n d: 3,\r\n e: [4, {\r\n h: 5\r\n }]\r\n },\r\n f: [6, 7],\r\n g: 8\r\n}\r\nconst objB = {\r\n a: 1,\r\n b: 2,\r\n c: {\r\n d: 3,\r\n e: [4, {\r\n h: 4\r\n }] // field h changed\r\n },\r\n f: [6, 7],\r\n g: 8\r\n}\r\nconst arrA = [objA, objB]\r\nconst arrB = [objA, objA]\r\n\r\nconsole.log(deepEqual(arrA, arrA))\r\nconsole.log(deepEqual(arrA, arrB))","IsDeferred":false}]}