I have an array of objects where an object can look like this:
{
"id": "d630baff-0caf-4c9a-88a2-fc4c99fab2a4",
"created": "2021-01-24 20:27:28",
"last_updated": "2021-01-20 13:17:44"
}
I want to sort based on either value that is largest of created
or last_updated
. I'm able to perform this in SQL by querying ORDER BY GREATEST(created, last_updated) DESC
, but how would I achieve this in Javascript? I have tried doing objs.sort((a, b) => (a.created > b.last_updated) ? 1 : -1)
but it doesn't result in the right order.