I am doing a to-do list, everything else works fine, but there's one issue that keeps bothering me. Since I don't want to set the date and the time as required input, so sometimes the date and time will be left blanket. But when I sorted the date ascending, the empty date's row will just pop up to the top. I hope it always is put to the bottom, no matter how I sort it. I tried to reassign the date to '2100-11-30T00:00:00'before compare function, but it's not working, and the console shows "Invalid Date". So I just wondering if there's any way to fix it? or Any solution to solve this problem?
const dateDown = document.querySelector(".dateDown")
dateDown.addEventListener("click", () => {
let arrayList = JSON.parse(localStorage.getItem("theList"));
arrayList.sort(function (a, b) {
let aDate = new Date(a.date) + a.time;
let bDate = new Date(b.date) + b.time;
if (aDate === null) {
aDate = new Date('2100-11-30T00:00:00');
}
console.log(aDate, bDate);
if (aDate < bDate) {
return 1;
} else if (aDate > bDate) {
return -1;
} else if (aDate == bDate) {
return 0;
}
})