How to modify this to arrow function


what is “Maximum call stack size exceeded”
why does it happen.

thank you for the answer.

Because you have set it up so that add calls itself indefinitely. What is the url of this challenge?

ES6: Write Higher Order Arrow Functions:
ES6: Use the Rest Operator with Function Parameters:

I consider that what it should be if combine these (func in func and (…args)) together in one line.

I do not think that is possible, because you need to be able to name the function which is returned by the IIFE (Immediately Invoked Function Expression) and it can be done like:

return function add(...args) {
 // code goes here

OR you would need to define it first with const and then return it like:

const add = (() => {
  const add = (...args) => args.reduce((a, b) => a + b, 0);
  return add; 

I just can not think of a way you can do it in one line, nor would I recommend it even if you could, because it is very unreadable like that.

1 Like