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

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