Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda