tweak the reduce exercise for beginner friendliness#168
tweak the reduce exercise for beginner friendliness#168Marlena wants to merge 2 commits intotimoxley:masterfrom
Conversation
timoxley
left a comment
There was a problem hiding this comment.
Some minor changes needed but this looks good! Thanks.
Wish we had these explanations for filter & map too.
| countMap[word] = ++countMap[word] || 1 // increment or initialize to 1 | ||
| return countMap | ||
| }, {}) // second argument to reduce initialises countMap to {} | ||
| return arr.reduce(function(accumulator, current_word) { |
There was a problem hiding this comment.
The original argument names were intended to be "semantic", related to the problem, rather than generic "accumulator". i.e. you're creating a map of counts for words.
Reduce functions can be hard to follow, so the idea is to embed as much semantic information into the argument names as possible. I'm open to better names, so long as they're not generic.
There was a problem hiding this comment.
I see your point. Thinking of it as an accumulator helped me understand reduce better, but using semantic naming is also helpful.
exercises/basic_reduce/problem.md
Outdated
| This single value is often called the accumulator because it is inside of this variable that values are accumulated. | ||
|
|
||
| When you use the javascript array method for reduce, many of the examples have a one return for this method, but it can be easier | ||
| to return the accumulator after performing your work. |
There was a problem hiding this comment.
I'd just drop this paragraph. Better to just present one style and not mention others.
exercises/basic_reduce/problem.md
Outdated
| accumulator = accumulator + current_value | ||
|
|
||
| return accumulator; | ||
| }, 0); |
There was a problem hiding this comment.
For consistency with other code samples, please drop unnecessary semicolons, unnecessary line breaks and use camelCase for variables. :D
…es back to original
In working through the reduce example at the Oakland Node school today, my pair and I thought that this tweak to the suggested solution along with a helpful hint would make the reduce example a little bit easier to solve.
Let me know if there are any additional tweaks or changes I should make.
Thanks for making this workshopper. It has been really fun!