From ddfc4c1cd5c9e04ff15efda301d6c15546932a2e Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Wed, 8 May 2024 09:22:32 -0400 Subject: [PATCH 1/4] Update employee nondestructively --- index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fccc9e603..520ff2f86 100644 --- a/index.js +++ b/index.js @@ -1 +1,15 @@ -// Write your solution in this file! +const employee = { + name: 'Yuriy', + streetAddress: 'None of your business' +}; + +const updateEmployeeWithKeyAndValue = (employee, key, value) => { + return { + ...employee, + [key]: value + }; +} + +const destructivelyUpdateEmployeeWithKeyAndValue = (employee, key, value) => { + return employee[key] = value; +} From efdb2c538587a9cdfc4f598eb7d039b85d920cd3 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Wed, 8 May 2024 09:26:29 -0400 Subject: [PATCH 2/4] Update employee destructively --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 520ff2f86..5947fb5f9 100644 --- a/index.js +++ b/index.js @@ -11,5 +11,6 @@ const updateEmployeeWithKeyAndValue = (employee, key, value) => { } const destructivelyUpdateEmployeeWithKeyAndValue = (employee, key, value) => { - return employee[key] = value; + employee[key] = value; + return employee; } From 07222b09e298a097f279c9910d3cfb1f7ee41060 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Wed, 8 May 2024 09:31:20 -0400 Subject: [PATCH 3/4] Delete property from new employee --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 5947fb5f9..c7430b50c 100644 --- a/index.js +++ b/index.js @@ -14,3 +14,9 @@ const destructivelyUpdateEmployeeWithKeyAndValue = (employee, key, value) => { employee[key] = value; return employee; } + +const deleteFromEmployeeByKey = (employee, key) => { + const newEmployee = {...employee}; + delete newEmployee[key]; + return newEmployee; +} From cea0a442105b93ee214480e7034ad3a4578426e2 Mon Sep 17 00:00:00 2001 From: Yuriy Ivanenko Date: Wed, 8 May 2024 09:32:57 -0400 Subject: [PATCH 4/4] Delete employee from original object --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index c7430b50c..922f2785b 100644 --- a/index.js +++ b/index.js @@ -20,3 +20,8 @@ const deleteFromEmployeeByKey = (employee, key) => { delete newEmployee[key]; return newEmployee; } + +const destructivelyDeleteFromEmployeeByKey = (employee, key) => { + delete employee[key]; + return employee; +}