So I reached a dilemma this week while trying to solve what seemed to be an easy problem, but I was wrong.
Sample code:
let arr = [
{ id: 'ae0123', cost: 100.00, orders: 5 },
{ id: 'ae0123', cost: 50.00, orders: 5 },
{ id: 'ae4321', cost: 75.00, orders: 1 }
]
So the problem was being able to map through the array and merge/sum the values if their unique identifiers match.
Any suggestions?
End result would look something like this:
[
{ id: 'ae0123', cost: 150.00, orders: 10 },
{ id: 'ae4321', cost: 75.00, orders: 1 }
]
Now of course the real application will not have statically typed ids, but they were written into this example. So please take that into consideration.
Thanks in advance!