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

203
Views
¿Cómo eliminar '-' de una fecha si es el último carácter?

Tengo una función que recibe 3 entradas del usuario: año, mes y día.

El usuario solo puede configurar el mes si se ha configurado el año. El día también se puede configurar solo si se configura el mes.

Al final, el objeto se ve así:

 updatedFields.push({ id: book.id, readIn: `${year}-${month}-${day}`, });

El problema es que el usuario no está obligado a informar nada. Entonces, si solo informa el año y el mes o solo el año, tendré algo como:

 "2020--" // if he only enters the year "2021-10-" // if he enters the year and month "2022-03-13" // if it enters year, month and day

La pregunta es: ¿cómo elimino el exceso - guiones?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Construya una matriz a partir de los valores posibles, filtre los que no existen y luego únalos por el separador.

 readIn: [year, month, day].filter(Boolean).join('-')
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar una expresión regular para eliminar los caracteres finales.

 updatedFields.push({ id: book.id, readIn: `${year}-${month}-${day}`.replace(/-+$/, '') });
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!