Is there a way to use the reduce function in order to return a list of objects? I am currently only able to return a single object with keys as project names and values as hours:
{
Name1: 9,
Name2: 10,
Name3: 30,
}
What changes can I make to my code to achieve a list of objects like this:
[{project: nameProj, hours: numProj}, {project: nameProj, hours: numProj},{project: nameProj, hours: numProj}]
This is my current code:
this.activities$
.pipe(map((e) => e.map((e) => e)))
.subscribe((e) => (this.dati = e));
this.aggregated = this.dati.reduce((acc: DataTable[], activity) => {
const projectName = `${activity.project?.customer.name} - ${activity.project?.name}`;
acc[projectName] = (acc[projectName] ?? 0) + activity.hours;
return acc
});
}, {});