I'm having trouble understanding the usage of the Array.sort
function. I have an array that looks like this:
[
{
"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"
}
]
I'm currently using things.sort((a, b) => b.votes - a.votes)
but this results in a random order when the votes are equal. What sort function should I use to get a stable, date based order when votes are equal?