03

Deep equal

25 min·senior·

Implement deepEqual(a, b) returning true iff a and b are structurally identical. Handle:

  • Primitives (incl. NaN === NaN should be true here)
  • Arrays (order matters)
  • Plain objects (key order doesn't matter)
  • Nested combinations
  • Cyclic references (don't infinite-loop)

You can ignore Map, Set, Date, class instances for v1.

Analyze time + space (depth-bounded recursion).

expected time · O(n) where n = total nodes
expected space · O(d) recursion (d = depth)
4 lines
⏵ run · no run yet · ctrl+enter