I've got this groupsArray
which I want to sort based on the days which are closest to 1 and the times
start and the end should be the earliest ones... I've tried a lot of stuff but I was unable to write a correct code to work...
I don't want to sort classtimes
, I want to sort groupsArray
based on classtimes
const groupsArray = [
{
classtimes: [
{
day: 4,
start: { hour: 21, minute: 0 },
end: { hour: 23, minute: 0 },
},
{
day: 3,
start: { hour: 17, minute: 0 },
end: { hour: 20, minute: 0 },
},
],
name: "6th Group",
},
{
classtimes: [
{
day: 1,
start: { hour: 18, minute: 0 },
end: { hour: 20, minute: 0 },
},
{
day: 1,
start: { hour: 14, minute: 0 },
end: { hour: 16, minute: 40 },
},
{
day: 2,
start: { hour: 16, minute: 0 },
end: { hour: 18, minute: 40 },
},
],
name: "5th Group",
},
];
I was thinking of writing something like this but It didn't work out...
groupsArray .sort((a,b) => a.classTimes.forEach(e => e.day > b.classTimes))