js lec 1 added

This commit is contained in:
2026-01-03 13:40:15 +10:00
parent cca7d57569
commit e6806a2366
18 changed files with 150 additions and 58 deletions

17
lectures/lec5/p3/task2.js Normal file
View File

@@ -0,0 +1,17 @@
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);