From 3a2b9abafb1ac1896e6530284d14b3a79ae8ece2 Mon Sep 17 00:00:00 2001 From: smsguy927 Date: Thu, 4 Mar 2021 10:08:33 +0000 Subject: [PATCH] Done. --- index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/index.js b/index.js index e69de29bb2..eb89847fa7 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,25 @@ +function updateObjectWithKeyAndValue(obj, key, val) { + // NON-DESTRUCTIVE! + let resultObj = {}; + resultObj = Object.assign(resultObj, obj); + resultObj[key] = val; + return resultObj; +} + +function destructivelyUpdateObjectWithKeyAndValue(obj, key, val) { + obj[key] = val; + return obj; +} + +function deleteFromObjectByKey(obj, key) { + // NON-DESTRUCTIVE! + let resultObj = {}; + resultObj = Object.assign(resultObj, obj); + delete resultObj[key]; + return resultObj; +} + +function destructivelyDeleteFromObjectByKey(obj, key) { + delete obj[key]; + return obj; +}