const input = [{diagramId: 123, data: [{id: 1, content: content1}]},
{diagramId: 123, data: [{id: 2, content: content2},
{id: 23, content: conent23}] },
{diagramId: 234, data: [{id: 3, content: content3}]}]
Desired output:
const output = [{diagramId: 123, data: [{id: 1, content: content1},
{id: 2, content: content2},
{id: 23, content: content23}]},
{diagramId: 234, data: [{id: 3, content: content3}]}]
As you can see above, I want to array method to combine objects that share the same property value (diagramId) to form a new object that condenses their other property together into an array under the other property.
I used for loops, but was rejected for PR due to readability issues. Is it possible to use Array.reduce() to do this?