In this lab, we'll create driver
objects and perform various operations on them.
Be sure to run the tests to get a feel for the types of problems this lab is
asking you to solve. In particular, you'll need to define a driver
object and
then apply certain updates (destructively and non-destructively) in various
functions.
You'll be writing four functions:
-
updateDriverWithKeyAndValue()
- this function should take in adriver
object, akey
and avalue
. The function should not mutate thedriver
parameter and return a newdriver
that has an updatedvalue
for thekey
passed in. -
destructivelyUpdateDriverWithKeyAndValue()
- this function should work the same asupdateDriverWithKeyAndValue()
but it should mutate thedriver
parameter passed in. -
deleteFromDriverByKey()
- this function should take in adriver
object and akey
. It should delete thekey
/value
pair for thekey
that was passed in from thedriver
object. This should all not actually mutate thedriver
passed in. -
destructivelyDeleteFromDriverByKey()
- this function should work the same asdeleteFromDriverByKey()
but it should mutate thedriver
passed in.
Good luck!
HINT: You might find deleteFromDriverByKey()
to be a bit hard to write
non-destructively. Think about how we learned to use Object.assign()
. What
happens if we do this:
const obj = { foo: 'bar' };
const newObj = Object.assign({}, obj);
newObj;
// => { foo: "bar" }
delete newObj.foo;
// => true
newObj;
// => {}
obj;
// => { foo: "bar" }
Hmmmmm...