I'm struggling to grasp the functionality of the Array.sort
method. In my case, I have an array structured as follows:
[
{
"votes": 3,
"suggestedDate": "2019-12-01T01:13:00.978Z"
},
{
"votes": 1,
"suggestedDate": "2020-05-14T21:55:05.879Z"
},
{
"votes": 1,
"suggestedDate": "2019-12-01T03:22:40.848Z"
}
]
Currently, I am utilizing
things.sort((a, b) => b.votes - a.votes)
. However, this order appears random when votes are equal. Can anyone recommend a sort function that will ensure a stable and date-based order in such scenarios?