I have an array in Javascript and I need to combine objects if they have equal reminder.date
const tasks = [
{
id: 1,
title: "call Tom",
reminders: {
date: "2022-02-01",
time: "09:30"
}
},
{
id: 2,
title: "Meet Bred",
reminders: {
date: "2022-02-01",
time: "10:30"
}
},
{
id: 3,
title: "Mail Susan",
reminders: {
date: "2022-03-01",
time: "19:00"
}
},
Output should be like this
const combinedTasks = [
{
id: 1,
tasks: ["call Tom", "Meet Bred"],
reminders: {
date: "2022-02-01",
time: "09:30"
}
},
{
id: 3,
tasks: ["Mail Susan"]
reminders: {
date: "2022-03-01",
time: "19:00"
}
}
I suppose that I need to use Array.reduce method but I dont have idea hot to do it correctly
titlekey is changed totasks. Is that intentional?. 2.) The combined object has the reminder time of the first object, how do you decide which time to take?