A build tool merges a user's config file over its defaults. Write deepMerge(base, override) that returns a new object and changes neither input:
base's keys.override: if its value is null, the key is removed from the result. If both base and override have plain objects (not arrays) at that key, merge them with the same rules. Otherwise the override's value replaces the base's value (arrays are replaced, not combined).Values in the result must not be shared with the inputs: copy nested objects and arrays.
Input: base = {"mode":"production","output":{"dir":"dist","clean":false},"plugins":["a"]}, override = {"output":{"clean":true},"plugins":["b"]} Output: {"mode":"production","output":{"dir":"dist","clean":true},"plugins":["b"]}
output is merged key by key, while plugins is replaced.
Input: base = {"devtool":"source-map","cache":true}, override = {"devtool":null} Output: {"cache":true}
null removes the key.
10^4 values in total.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #741 Deep Merge Two Configs. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.