Write a function that determines if two objects are deeply equal.
HardProblem Statement
Write a function that determines if two objects are deeply equal.
Sample Input
obj1 = { a: 1, b: { c: 2 } }
obj2 = { a: 1, b: { c: 2 } }Sample Output
true
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Check if two objects are deeply equal
function deepEqual(obj1, obj2) {
// Check for reference equality
// If either is not an object, compare values directly
// Compare keys and recursively compare properties
}
console.log(deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }));
Input
obj1 = { a: 1, b: { c: 2 } }
obj2 = { a: 1, b: { c: 2 } }Expected Output
true