---
tags: sleeping duck
---
# Questions
## Part 1
### Question 1
`setState(updaterFunction)` allows you to execute an update function on the component's internal `state` after all other `setState` functions are called.
### Question 2
Directly mutating `state` in a component is a bad pattern as this can introduce unintended side effects. New state references should be returned instead.
Spreading inside the map returns the other properties inside the object, rather than naming them directly when returning the object.
## Part 2
### Question 1
Using an `Array` and referencing elements by their `index` can be inefficent where a large number of elements are stored, as well as resulting in possibly more complex code.
Using an `Array` iterator also means any operations on the `Array` are of an O(n) complexity, meaning the time taken to execute an operation of one or more elements is depedant on the size of the `Array`.
A better structure that would give an O(1) complexity would be an `Object` or `Map` which could be constructed by a know index, i.e. `id` which could take the place of the `Array` index. This means we could run an operation using a direct reference to the element in the `Object` or `Map` rather than using an iterator.