This function merges two dictionaries, using the value from the later dictionary to resolve conflicts.
I have 5 tests that the program passes successfully:
const cases = [
[[{ a: 'uno', b: 'due' }, { c: 'tre' }], { a: 'uno', b: 'due', c: 'tre' }],
[[{ a: 'uno', b: 'due' }, { a: 'uno' }], { a: 'uno', b: 'due' }],
[[{ a: 'uno', b: 'due' }, { a: 'due' }], { a: 'due', b: 'due' }],
[[{ a: 'uno' }, { c: 'tre' }], { a: 'uno', c: 'tre' }],
[[{ a: 'uno' }, {}], { a: 'uno' }],
];
How can I improve this code?
const objects = (first, second) => {
const object = {};
for (item of Object.keys(first)) {
object[item] = first[item];
}
for (item of Object.keys(second)) {
object[item] = second[item];
}
return object;
};