Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda