tasks = [
{
textTask: 'Задача 1',
user: {
id: 1,
name: 'User1'
}
},
{
textTask: 'Задача 2',
user: {
id: 2,
name: 'User2'
}
},
{
textTask: 'Задача 3',
user: {
id: 1,
name: 'User1'
}
},
{
textTask: 'Задача 4',
user: {
id: 1,
name: 'User1'
}
},
{
textTask: 'Задача 5',
user: {
id: 2,
name: 'User2'
}
}
]
tasks = [
{
user: {
id: 1,
name: 'User1',
tasks: [
{
textTask: 'Задача 1'
},
{
textTask: 'Задача 3'
},
{
textTask: 'Задача 4'
}
]
}
},
{
user: {
id: 2,
name: 'User2',
tasks: [
{
textTask: 'Задача 2'
},
{
textTask: 'Задача 5'
}
]
}
}
]
Object.values(tasks.reduce((acc, { user: { id, name }, ...n }) => {
(acc[id] = acc[id] || { user: { id, name, tasks: [] } }).user.tasks.push(n);
return acc;
}, {}))