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

132
Vistas
Sort data by time slot in javascript

I have to sort data coming from the server dynamically by differents fields. It is working perfectly with all the fields except by time slot field. I have to sort data by time slot field in ascedening order, the problem is that the time slot is string e.g: "09:00-09:59".

My sorting function is:

function sortArray(array: any[], direction: string, extractor: (any) => any): any[] {
  return array.sort((e1, e2) =>
    (direction === 'asc' && extractor(e1) > extractor(e2)) || (direction !== 'asc' && extractor(e1) < extractor(e2))
      ? 1
      : -1
  );
}

How can I fix it? If anyone know then please let me know. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your sortArray function is fine. You have to check sort.active and sort.direction are updating correctly.

Try like this:

  console.log('this.sort.active', this.sort.active);
  console.log('this.sort.direction', this.sort.direction);

And If they are not updating then this is the problem. Then revise your logic of updating these things.

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