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

117
Vistas
Sort Array with String Dates (JavaScript)

I have this piece of code for sorting:

compareDates(a: string, b: string, isAsc: boolean) {
    // splitting the string after on dot, because the date string is like: 14.06.2022
    var d1Splitted = a.split('.');
    var d2Splitted = b.split('.');
    const d1 = Date.parse(d1Splitted[2] + '-' + d1Splitted[1] + '-' + d1Splitted[0]);
    const d2 = Date.parse(d2Splitted[2] + '-' + d2Splitted[1] + '-' + d2Splitted[0]);

    return isAsc ? Number(d1) - Number(d2) : Number(d2) - Number(d1);
  }

wenn I sort a list by date I get the well sorted list, but after few times of clicking on sort button I get this: enter image description here

about 4 years ago · Juan Pablo Isaza
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