So I am trying to sort an array so that the first item would be the same as the current day and month or the closest entry.
My array looks like this:
[
[
"Firstname Lastname",
"1979-01-03",
"40"
],
[
"Firstname Lastname",
"1996-01-23",
"23"
],
[
"Firstname Lastname",
"1977-01-28",
"41"
],
[
"Firstname Lastname",
"1983-03-11",
"35"
],
[
"Firstname Lastname",
"1977-03-30",
"41"
],
[
"Firstname Lastname",
"1975-05-08",
"43"
]
]
I did figure out how to sort the array based on the day of the month but then it ignores the month itself
relativeYearDay(date) {
let differenceDay = new Date(date).getDate() - new Date().getDate();
if (differenceDay < 0) {
differenceDay += 365;
}
return differenceDay;
}
getUpcomingBirthdays() {
return this.birthdays.slice(0).sort((a, b) => {
return this.relativeYearDay(a[1]) - this.relativeYearDay(b[1]);
});
},
Like I mentioned this returns a sorted array based on the day of the month.
How would I do it for both day and month?
"yyyy-") and sort by what's left.