js lec 1 added
This commit is contained in:
17
lectures/lec5/p3/task2.js
Normal file
17
lectures/lec5/p3/task2.js
Normal 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);
|
||||
Reference in New Issue
Block a user