Implement mergeDeep(a, b)
Write mergeDeep(a, b) that recursively merges b into a, without mutating either input, and returns a brand-new object:
- If both
a[key]andb[key]are plain objects, merge them recursively. - Otherwise,
b[key]wins outright, this includes arrays: an array inbfully replaces one ina, it doesn't merge element-by-element.
mergeDeep({ a: { x: 1 }, tags: ["old"] }, { a: { y: 2 }, tags: ["new"] });
// { a: { x: 1, y: 2 }, tags: ["new"] }