'Typescript Question:Functiong Type in Typescript Exercise 14

I am learning typescript in typescript exercise

in this subject solution,there is a function:

function toFunctional<T extends Function>(func: T): Function {
  const fullArgCount = func.length;
  function createSubFunction(curriedArgs: unknown[]) {
    return function(this: unknown) {
      const newCurriedArguments = curriedArgs.concat(Array.from(arguments));
      if (newCurriedArguments.length > fullArgCount) {
        throw new Error('Too many arguments');
      }
      if (newCurriedArguments.length === fullArgCount) {
        return func.apply(this, newCurriedArguments);
      }
        return createSubFunction(newCurriedArguments);
      };
   }
   return createSubFunction([]);
}

I dont understand this line:

const fullArgCount = func.length;

cause in that after,parameter func is a function,but whats the value of func.length

and whats newCurriedArguments actually mean ?



Solution 1:[1]

and whats newCurriedArguments actually mean ?

const newCurriedArguments = curriedArgs.concat(Array.from(arguments));

newCurriedArguments is the result of concatenating two arrays:

  1. curriedArgs from createSubFunction() function, as the inner function where newCurriedArguments is declared has access to its parent function variables, and curriedArgs is one of them.
  2. arguments which is the arguments of the function itself.

So you could say newCurriedArguments is the arguments of both the function and its parent.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moaaz Bhnas