EasyPythonJavaScriptTypeScript

Deep Equal

ObjectsRecursionFunctions

Implement solve(a, b) that performs a structural equality check between
two values. Return true if they are deeply equal, false otherwise.

Rules

  • Primitives: use ===.
  • Arrays: same length, each element deeply equal.
  • Plain objects: same own keys (order-independent), each value deeply equal.
  • null is not deeply equal to {}.

Examples

  • solve({a:1,b:[2,3]}, {b:[2,3],a:1})true
  • solve([1,[2,3]], [1,[2,4]])false

Sample tests

Test #1Both null
Input: [null,null]
Output: true
Test #2null vs empty object
Input: [null,{}]
Output: false
Test #3Nested array differs at leaf
Input: [[1,[2,3]],[1,[2,4]]]
Output: false
Test #4Same nested object with different key order
Input: [{"a":1,"b":[2,3]},{"a":1,"b":[2,3]}]
Output: true
Test #5Deeply nested equal objects
Input: [{"x":{"y":{"z":42}}},{"x":{"y":{"z":42}}}]
Output: true