Fill In Options So Every Key Is Set
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write withDefaults(options, defaults), where options is an object whose properties are all optional: return a new object with every option, taking each one from options when it's set (not undefined, so 0 and empty strings count as set) and from defaults otherwise. Type it so the result has every key required, and so defaults must give every option a value of the right type.
Your code must pass
- Uses defaults for missing options
- Treats an undefined option as missing
- Leaves both objects unchanged
- Has no type errors
- Every key is required in the result
- Rejects defaults that miss a key
- Rejects a default of the wrong type