re: Functional Programming in JavaScript VIEW POST


Hey Hunter!

Great post, thanks for sharing!

I think I spotted a slight mistake with your section around reduce .

The function signature of reduce is

const reducer = (accumulator, currentValue) => accumulator + currentValue;

i,e accumulator first, then currentValue whereas your description says "Notice how we get that second parameter to the function? That's called an accumulator, " and your code block has them flipped too:

const sum = numberList.reduce((currentSum, number) => currentSum + number, 0); // 10

You may not have noticed as in this case it would still calculate correctly regardless of the naming of the variables for a simple sum like this. Just thought you should know as it threw me off slightly reading it!


The currentSum is meant to be the accumulator, so I think the code block is correct it's just the language above it that's ambiguous. I had intended it to be something that meant closer to "notice how we have a new parameter" rather than implying the number was the accumulator. Either way, I'll go back and try and clear that language up. Thanks for pointing this out!

code of conduct - report abuse