From 927799899635f1c8f1ecab847dd29a7d61ba6ea9 Mon Sep 17 00:00:00 2001 From: tsomielvis Date: Tue, 16 Jul 2024 20:46:04 +0300 Subject: [PATCH] Create index.js latest --- index.js latest | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 index.js latest diff --git a/index.js latest b/index.js latest new file mode 100644 index 000000000..7ae8a4729 --- /dev/null +++ b/index.js latest @@ -0,0 +1,31 @@ +let employee = { + name: "John Doe", + streetAddress: "123 Main St" + }; + + // Function to update employee with key and value (non-destructively) + function updateEmployeeWithKeyAndValue(employee, key, value) { + return { + ...employee, + [key]: value + }; + } + + // Function to update employee with key and value (destructively) + function destructivelyUpdateEmployeeWithKeyAndValue(employee, key, value) { + employee[key] = value; + return employee; + } + + // Function to delete property from employee object (non-destructively) + function deleteFromEmployeeByKey(employee, key) { + let newEmployee = { ...employee }; + delete newEmployee[key]; + return newEmployee; + } + + // Function to delete property from employee object (destructively) + function destructivelyDeleteFromEmployeeByKey(employee, key) { + delete employee[key]; + return employee; + }