FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Deep Merge

25mins

Implement a function deepMerge(...objs) that merges multiple objects into a single object recursively.

The function should:

  • Accept any number of objects as arguments.
  • Merge nested objects recursively.
  • For properties with the same key, values from later objects should overwrite earlier ones.
  • Return a new object without mutating the original objects.

Example

const obj1 = { a: 1, b: { c: 2 } }; const obj2 = { b: { d: 3 }, e: 4 }; const result = deepMerge(obj1, obj2); console.log(result); // { a: 1, b: { c: 2, d: 3 }, e: 4 }

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests