Explorer
Node.js

Write a function `deepEqual(a, b)` that performs a deep comparison of two values (objects, arrays, primitives).

Problem Statement

Write a function `deepEqual(a, b)` that performs a deep comparison of two values (objects, arrays, primitives).

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Handle primitives first with strict equality. šŸ’” Hint 2: For objects/arrays, compare keys and recurse on values. šŸ’” Hint 3: Check same type, same number of keys, then recursively compare each key value pair. āœ… Solution: ```javascript function deepEqual(a, b) { if (a === b) return true; if (a == null || b == null) return false; if (typeof a !== typeof b) return false; if (typeof a !== "object") return false; const keysA = Object.keys(a); const keysB = Object.keys(b); if (keysA.length !== keysB.length) return false; return keysA.every(key => deepEqual(a[key], b[key])); } ```

Deep Equal

Hard
Write a function `deepEqual(a, b)` that performs a deep comparison of two values (objects, arrays, primitives).
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[true,false,true,true]