Struggling to reimagine the _.defaults function from underscore.js, I keep encountering this pesky error:
Error message: should copy source properties to undefined properties in the destination object‣ AssertionError: expected { a: 'existing' } to deeply equal { a: 'existing', b: 2, c: 3, d: 4 }
Highlighted are the missing conditions:
-should copy source properties to undefined properties in the destination object and return the updated object
Showcasing my current code snippet:
_.defaults = function (destination, source) {
Object.keys(destination).forEach(key => {
if (destination[key] === undefined || destination[key] === null) {
destination[key] = source[key];
}
})
return destination;
};