I have two sorted arrays, and combined them 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)
How to sort listC base on the dateTime?
SO I was thinking to get the a new dateTimeList contains only the dateTime, then sort this list, and somehow sort the listC
dateTimeList = this.listA
.map(x => x.dateTime_ISO)
.concat(this.listB.map(x => x.dateTime));
But is there any robust way to sort this dateTimeList?
If it cannot be done just because the two lists have different field name (dateTime_ISO and dateTime), then just pretend they are the same. I could modify them to be the same in the database.
Appreciate for any help.