hello,
the second day I’m struggling with one task.
the condition of task. is
Write a function called “extend”.
Given two objects, “extend” adds properties from the 2nd object to the 1st object.
Notes:
* Add any keys that are not in the 1st object.
* If the 1st object already has a given key, ignore it (do not overwrite the property value).
* Do not modify the 2nd object at all.
var obj1 = {
a: 1,
b: 2
};
var obj2 = {
b: 4,
c: 3
};
extend(obj1, obj2);
console.log(obj1); // --> {a: 1, b: 2, c: 3}
console.log(obj2); // --> {b: 4, c: 3}
At first I’m trying to compare obj1 and obj2 keys
I tryide to compare it with for( ){for(){ }} loops but it
var aProps = Object.keys(obj1);
var bProps = Object.keys(obj2);
for(var i = 0; i < aProps.length; i++){
for(var j= 0; j < bProps.length; j++){
let arr = [];
if(aProps[i] !== bProps[j]){
arr.push(bProps[j]);
}
}
}
But it isn’t good solution then look througth some forume but didn’t found any appropiate solution.
May somebody can suggest some good artikle about it?