Problem, as an interviewer would state it:
"Implement deepMerge(target, source) — recursively merging source into target, combining NESTED objects field-by-field rather than overwriting them wholesale, and returning a genuinely NEW merged object without mutating either input."
Examples:
deepMerge({a:1, b:{c:2, d:3}}, {b:{c:99}, e:5});
// {a:1, b:{c:99, d:3}, e:5}
Clarifying questions expected:
- When BOTH target and source have a nested object at the same key, should they be recursively merged, rather than source simply overwriting target's whole object?
- What is the real, correct behavior for an ARRAY value — should two arrays at the same key be merged together, or should source's array simply replace target's?
- Should either input object be mutated, or must a genuinely new result be returned?
Code / implementation expected: Yes — real, direct proof of recursive nested merging, confirmation the original target is never mutated, and — critically — confirmation of the correct, real array-replacement (not array-merging) behavior.