We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Theragingwalrus • 6 years ago

Thanks for the explanation! It helped a lot. Now I'm stuck here:


const sum = (init = 0, ...values) => values.reduce( (acc, value) => acc + value, init );


Sum is a function, the variable amount of parameters get put into an array values, that much is clear. Then this sum function returns the output of values.reduce(). What happens here in this is what I don't understand.

Matthieu Wipliez • 6 years ago

What values.reduce does is iterate over the values array and run the (acc, value) => acc + value function for every value. acc is set from the return value of the function, and its initial value is init.

Theragingwalrus • 6 years ago

I was following along until you introduced some things without explaining what they are (currying, partial application, const for defining a function?) Can you explain those? And what does this syntax mean:

const add = x => y => x + y;

Matthieu Wipliez • 6 years ago

Thank you for your comment, you're right I've forgotten a few things there :) I've updated the playground with additional explanations and with the ES5 equivalent to make it easier to understand. The 'const add = x => ...' is really the same as 'var add = function(x) { ... }', it's just that 'const' prevents your function from being redefined accidentally. Hope this helps! Don't hesitate if there are other things I could improve. Thanks!