-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (27 loc) · 822 Bytes
/
index.js
File metadata and controls
34 lines (27 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var recipes = {
chocolate: "two bars",
sugar: "five cups",
honey: "seven teaspoons"
}
//object assign where keeps original recipe the same
//and makes new object clone and adds new property
function updateObjectWithKeyAndValue(obj, key, value){
var newThing = Object.assign({}, obj, {[key]: value})
return newThing;
}
//object assign where changes original object
function destructivelyUpdateObjectWithKeyAndValue(obj, key, value) {
obj[key] = value;
return obj;
}
function deleteFromObjectByKey(object, key) {
//first assign to new Object as a clone, dont need to write keys, just the old object
//then can safely delete from new object
Object.assign({}, object);
delete Object[key];
return Object;
}
function destructivelyDeleteFromObjectByKey(object, key) {
delete object[key];
return object;
}