I have contacts that have SMS messages associated with them. Each sms record has properties such as time
. Time is an timestamp string formatted as this example
2022-04-29T16:10:43-06:00
I am trying to sort this array of sms messages so that the latest one is the last one and the earliest one is the first one in the array. I thought I had it nailed down but apparently I don't. Its still not perfectly sorting at all.
this.getRecent()
.then(contacts => {
const sorted = contacts.map(contact => {
contact.sms = contact.sms.sort((a,b) => (a.time.localeCompare(b.time));
return contact;
});
// rest of code here
})
.catch(err => this.handleError(err));