My goal is to arrange my array of objects with date values in descending and ascending order.
Here is the code I am using:
function comp(a, b) {
return new Date(a.jsDate) - new Date(b.jsDate);
}
function compNewestFirst(a, b) {
return new Date(b.jsDate) - new Date(a.jsDate);
}
It is important to note that the JS Date format is valid for the new Date() method.
Although I am able to sort it in ascending order, I am facing issues with sorting it in descending order. I have attempted the following:
return new Date(b.jsDate) + new Date(a.jsDate);
Currently, I am unable to sort by the newest date first, as it only works in the oldest date first scenario.
Thank you.