Write a function that merges two deeply nested objects, combining properties without overwriting them.
HardProblem Statement
Write a function that merges two deeply nested objects, combining properties without overwriting them.
Sample Input
{ a: { b: 1, c: 2 } }, { a: { d: 3 } }Sample Output
{ a: { b: 1, c: 2, d: 3 } }
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Merge two deeply nested objects without overwriting properties
function deepMerge(obj1, obj2) {
// Recursively merge each property of the objects
}
console.log(deepMerge({ a: { b: 1, c: 2 } }, { a: { d: 3 } }));
Input
{ a: { b: 1, c: 2 } }, { a: { d: 3 } }Expected Output
{ a: { b: 1, c: 2, d: 3 } }