Coding Challenge - #11: Deep Object Merge

Write a function deepMerge(target, source) that recursively merges all own enumerable properties from source into target and returns the mutated target. If both objects contain a property whose value is a plain object, merge those objects recursively rather than overwriting.

function deepMerge(target, source) {
  // your code here
}

Rules:

  • Mutate and return the target object.
  • Non-object values or arrays should be overwritten by the source value.
  • Must handle nested objects of arbitrary depth.

Post your solution as a reply. Answer goes up in about a day.

This feels like something @senocular or @krilnon can do in their sleep!

It is fun to see how different people approach these kinds of problems.

Short and concrete wins because teams use it under pressure.