diff --git a/objects lab b/objects lab new file mode 100644 index 000000000..7ae8a4729 --- /dev/null +++ b/objects lab @@ -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; + }