Files
uni-web-site/old/lectures/lec5/p3/task2.js
2026-02-26 21:55:48 +10:00

17 lines
419 B
JavaScript

function updateObject(oldObject, newObject) {
const [newKey, newValue] = Object.entries(newObject)[0];
if (newKey in oldObject) {
oldObject[newKey] += newValue;
} else {
oldObject[newKey] = newValue;
}
return oldObject;
}
const oldObject = { 1: 10, 2: 20, 3: 30 };
const newObject = { 2: 15 };
const updatedObject = updateObject(oldObject, newObject);
console.log(updatedObject);