Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bugsysha's avatar

OK, list here some examples since we are not making any progress here. I'm getting ultra confused 🤯

kendrick's avatar

Thank you for you patience @bugsysha

id |       date       |     time      |

1  | 2020-01-22 | 12:00:00   |
2  | 2020-01-20 | 12:00:00   |
3  | 2020-01-20 | 10:00:00   |

With

orderedPaths: function () {
    return _.orderBy(this.paths ? this.paths : [], 'date', 'asc');
}

2
3
1

// should be: 3,2,1

With

orderedPaths: function () {
return [...this.paths].sort((a, b) => {
    return `${a.date} ${a.time}` - `${b.date} ${b.time}`;
});
}
1
2
3
bugsysha's avatar
bugsysha
Best Answer
Level 61
return [...this.paths].sort((a, b) => {
  const aDateTime = `${a.date} ${a.time}`;
  const bDateTime = `${b.date} ${b.time}`;
  if (aDateTime > bDateTime) {
    return 1;
  }
  if (bDateTime > aDateTime) {
    return -1;
  }

  return 0;
});
kendrick's avatar

Sorry about the confusion and additional headaches, will next time first display the order, and try to make no typos.

bugsysha's avatar

Since you are so nice here you go

return [...this.paths].sort((a, b) => (new Date(`${a.date} ${a.time}`)) - (new Date(`${b.date} ${b.time}`)));
kendrick's avatar

This will get back to 1,2,3. (also sorry about the other thread, would have loved to give you the ba)

bugsysha's avatar

This will get back to 1,2,3.

Should work, but like I said who cares.

also sorry about the other thread, would have loved to give you the ba

No problem. For me my suggestion was a cleaner and more expressive approach.

kendrick's avatar

No problem

You are right, actually also using your cleaner method.

Previous

Please or to participate in this conversation.