Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
¿Cómo reconstruir una función con tres parámetros a uno?

Aquí tengo un fragmento de código getIsoDate que funciona exactamente como quiero. Pero luego necesito pasarlo más allá como un solo argumento en lugar de tres argumentos como tengo ahora (día, mes, año). Es por eso que recibo el error: esperaba 3 argumentos, pero obtuve 1.ts (2554)

Entonces, para deshacerme del error, necesito reconstruir getIsoDate que tiene un argumento pero la misma función y estoy luchando por entender cómo lograrlo, deshacerme del día, mes, año y usar solo un valor? ¿O hay otro enfoque? ¿Puedes darme una pista o consejo sobre cómo empezar?

 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 answers
Answer question

0

Puede desestructurar los argumentos así si pasa un objeto con las claves correspondientes:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!