I have combined two sorted arrays into a new listC.
listA = [
{id:"1234435", name:"apple", dateTime_ISO:"2019-01-15 17:27:30"},
{id:"1234435", name:"orange", dateTime_ISO:"2019-01-15 10:25:30"},
{id:"1234435", name:"banana", dateTime_ISO:"2019-01-15 10:25:02"},
{id:"1234435", name:"pear", dateTime_ISO:"2019-01-15 07:21:52"},
{id:"1234435", name:"lemon", dateTime_ISO:"2019-01-15 07:22:24"},
]
listB = [
{id:"1234435", name:"bread", dateTime:"2019-01-15 17:27:34"},
{id:"1234435", name:"rice", dateTime:"2019-01-15 09:25:30"},
{id:"1234435", name:"noodle", dateTime:"2019-01-15 07:25:02"},
{id:"1234435", name:"pie", dateTime:"2019-01-15 07:06:52"},
{id:"1234435", name:"cake", dateTime:"2019-01-15 06:22:24"},
]
listC = this.listA.concat(this.listB)
What's the best way to sort listC based on the dateTime?
One approach could involve creating a new list of only the dateTimes, sorting that list, and then sorting listC accordingly.
dateTimeList = this.listA
.map(x => x.dateTime_ISO)
.concat(this.listB.map(x => x.dateTime));
Is there a more robust method for sorting this dateTimeList?
If the issue is due to the different field names in the two lists (dateTime_ISO and dateTime), we can consider treating them as equivalent. The database can be updated accordingly.
Any help would be greatly appreciated.