- Practice using forEach
- Practice using sort
- Practice using reduce
Be sure to run the tests to get a feel for the types of problems this lab is asking you to solve.
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 intdestructivelyUpdateDriverWithKeyAndValue
- 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 actuallymutate
thedriver
passed indestructivelyDeleteFromDriverByKey
- 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
var obj = { foo: 'bar' }
var newObj = Object.assign({}, obj)
newObj // { foo: 'bar' }
delete newObj.foo // true
newObj // {}
obj // { foo: 'bar' }
Remember the workflow:
-
Run
learn-test
. -
Read the errors; vocalize what they're asking you to do.
-
Write code; repeat steps 1 and 2 often until a test passes.
-
Repeat as needed for further tests.
-
Run
learn submit
when finished!
If you open up test/indexTest.js
, you will see that in the beforeEach
block we initialize our driver
array values so that you can focus on what really matters — understanding how to manipulate arrays in JavaScript.
View Javascript Object Lab on Learn.co and start learning to code for free.