I am currently working on replicating the functionality of an Outlook mailbox by organizing a list of Outlook emails based on their conversation ID. However, I am facing the challenge of needing to sort my list twice - once to order the emails in each group from newest to oldest, and then to sort the conversation list itself from oldest to newest. This requires comparing the first item in each array (which should be the newest once sorted) to achieve the desired outcome.
Here is how the object looks once grouped:
{"sdfjskldfjks" : [{from: "joe", received_date:"07/11/1990 5:30PM"}], "dfjsakldfjhsa" : [{from: "john", received_date:"07/12/1990 5:30PM"},{from: "jake", received_date:"07/12/1989 5:30PM"}]}
Below is the function I am using to group the emails:
const cleanFolder = computed(() => {
if(currentFolder.value == null){
return []
}
function groupBy(arr: any[], property: string) {
return arr.reduce(function (memo: { [x: string]: any[]; }, x: { [x: string]: string | number; }) {
if (!memo[x[property]]) { memo[x[property]] = []; }
memo[x[property]].push(x);
return memo;
}, {});
};
return groupBy(currentFolder.value.emails,'conversation_id')
})
Although I am familiar with sorting arrays, I am struggling to sort based on an object as seen in this case. Any guidance or suggestions would be greatly appreciated!