Solution Review
Review with explanations. (3 min. read)
We'll cover the following...
We'll cover the following...
assoc
We learned that a pure function must follow 2 rules
- Same inputs => same outputs
- No side-effects
assoc currently mutates the input object, which is a side-effect.
Cure it by cloning the input and merging the desired properties.
getNames
This was sort of a trick question. getNames is pure if you remove console.log.
You can now refactor it to a single-line statement, if you prefer.
append
This is impure because it mutates the input list. Like assoc, you can return a clone with the desired output.
sortAscending
Once again we’re using an impure Array method, sort. Cloning the input purifies us right up.