repl.it
@Tyledelphia/

extend-1

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function extend(obj1, obj2) {
  for (let key in obj2) {
    if (obj1[key] === undefined) {
      obj1[key] = obj2[key];
    }
  }
  return obj1;
}

/*
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.
*/
Native Browser JavaScript