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

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

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