Exercise · Objects · lesson 12 of 13
Exercise: default settings
Write a function function withDefaults(options) that returns a new settings object: it has every property of options, and the properties size and color that options lacks come from the default settings { size: "M", color: "black" }.
withDefaults({ size: "L" })→{ size: "L", color: "black" }withDefaults({})→{ size: "M", color: "black" }withDefaults({ color: "red", logo: "cat" })→{ size: "M", color: "red", logo: "cat" }
Constraints: options is an object with string values, possibly empty; options itself does not change, and the result is a new object every time, even when options has both properties; the order of keys in the result does not matter.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.