I need to sort array of object by 3 criteria:
- Time (earliest)
- Role (a-z)
- User (a-z)
So first I need to sort them out by the start date, then that sorted array I need to kinda make groups of roles and sort them alphabetically (but still maintain sorting by time), and in the end, if the shifts let say are the same role and start at the same time sort them by user name.
Here is a simplified object
const array = [{
role: "Host"
start: "2022-08-08T02:30:00+00:00"
user: "Joe Doe"
}]
Maybe is best to start off by sorting out the roles first, and that small group of roles sort by the time or I don't know, if you have any ideas I would appreciate any suggestion, Thanks!!
Ok so I guess you need a bit more data: Here is initial array
const array = [
{
role: "Host"
start: "2022-08-08T02:30:00+00:00"
user: "AJoe Doe"
},
{
role: "Cook"
start: "2022-08-08T00:30:00+00:00"
user: "DJoe Doe"
},
{
role: "Host"
start: "2022-08-07T23:30:00+00:00"
user: "CJoe Doe"
},
{
role: "Host"
start: "2022-08-07T23:30:00+00:00"
user: "BJoe Doe"
},
{
role: "Cook"
start: "2022-08-08T02:30:00+00:00"
user: "EJoe Doe"
}]
And here is what I need to get (sorted out by the role, time and in the end by user:
const array = [
{
role: "Cook"
start: "2022-08-08T00:30:00+00:00"
user: "DJoe Doe"
},
{
role: "Cook"
start: "2022-08-08T02:30:00+00:00"
user: "EJoe Doe"
},
{
role: "Host"
start: "2022-08-08T02:30:00+00:00"
user: "AJoe Doe"
},
{
role: "Host"
start: "2022-08-07T23:30:00+00:00"
user: "BJoe Doe"
},
{
role: "Host"
start: "2022-08-07T23:30:00+00:00"
user: "CJoe Doe"
}]