I have an array of objects for a project in which they work kind of like entries to a blog. I'm then attempting to sort the entries by the publication date of each entry (recents first), however, apparently the sorting function isn't considering the year value or maybe some other issue I'm missing.
Example situation
One of the entries was published the 23 of June (6) in 2019 and it is the first value of the output array because it's the entry with the most recent date. BUT if I try to change its year to something like 2005, it will stay at the top like if the function would be ignoring the year. I also tried changing it into 0 but the result remained the same.
Code I used
Example Item in the array of objects
For the date I used another array in which index 0 refers to the Day, index 1 to the Month and index 2 to the Year.
[{Id: "P3", Date: [23, 6, 2019]}, ...]
Sorting function
I use the three values of the Date arrays to calculate the total number of days since day 0 and compare them (the biggest number of days = the most recent entry)
array.sort((a, b) => ((a.Date[0] + (a.Date[1] * 30) + (a.Date[2] * 365)) < (b.Date[0] + (b.Date[1] * 30) + (b.Date[2] * 365)) ? 1 : -1)).map(item => item.Id)
The function outputs an array with the Ids of the entries they refer to, supposedly, in order.
Any help fixing my code will be helpful and appreciated :)
31and366instead of30and365.Dateobjects instead of arrays?0for equal items!