Merge settings
A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.
The task
Return a new object combining `base` and `override`. When both sides hold a plain object (made with `{}`) under the same key, merge those recursively. Anything else from `override` (arrays, dates, numbers, `null`) replaces what `base` had. Do not change either input.
What this exercise teaches
Spreading base gives a fresh top-level copy, and recursion builds fresh copies of every nested object it merges, so neither input is touched. The plain-object test keeps arrays, Dates and null as whole values.
A hint if you get stuck
Start from `{ ...base }`, then go through the entries of `override`. Recurse only when both values are plain objects: `Object.getPrototypeOf(v) === Object.prototype`.
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.