A
A
asmodeus13th2021-06-21 14:39:52
JavaScript
asmodeus13th, 2021-06-21 14:39:52

How to stop function return recursion?

The recursive function must accumulate numbers into an array and be called with additional parentheses (as in the example below) . We want the function to return an array of args . This means that you need to come up with a condition for exiting the recursion. I can't figure out how.

function curry(...args) {
  return (num) => curry(...args, num)
}
curry(2)(8)(5)  // вернёт function, а должно быть [2, 8, 5]
curry(1)(0)(9)(3)(12)  // вернёт function, а должно быть [1, 0, 9, 3, 12]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-21
@asmodeus13th

Currying requires a function with a fixed number of arguments.
A function that uses residual parameters, such as f(...args), cannot be curried this way.

Source .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question