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

354
Visualizações
How to rebuild a function with three parameters to one?

I have here a piece of code getIsoDate that works exactly as I want. But later I need to pass it further as one single argument instead of three arguments like I have now (day, month, year). Thats why I get the error - Expected 3 arguments, but got 1.ts(2554)

So in order to get rid of the error I need to rebuild getIsoDate that it has one argument but the same function and I am struggling to understand how to achieve that, get rid of day, month, year and use only one value? Or is there another approach? Can you please give me a hint or tip how to start?

const getIsoDate = (day: string, month: string, year: string) => {
  if (day && year && month && parseInt(year) > 999)
    return new Date(`${year}-${month}-${day}T12:00:00`).toISOString();
  else if (!day && !month && (!year || parseInt(year) < 1000)) return undefined;
  else return "Invalid Date";
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can destructure the arguments like so if you pass in an object with the corresponding keys:

const getIsoDate = ({ day, month, year}) => {
  if (day && year && month && parseInt(year) > 999)
    return new Date(`${year}-${month}-${day}T12:00:00`).toISOString();
  else if (!day && !month && (!year || parseInt(year) < 1000)) return undefined;
  else return "Invalid Date";
}

// exmaple usage
const someDate = { day: '25', month: '04', year: '2022' }
console.log(getIsoDate(someDate))

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