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

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

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 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!