I have been stuck in one situation where I need data for my easy invoice. I am using using in node.js. I want to make wrap duplicate values in one with sum of quantities.
I have products array
`[
{
quantity: 1,
description: 'Node Training Package',
'tax-rate': -40.5,
price: 20
},
{
quantity: 1,
description: 'Node Training Package',
'tax-rate': -40.5,
price: 20
},
{
quantity: 1,
description: 'Angular crash course',
'tax-rate': -40.5,
price: 35
},
{
quantity: 1,
description: 'Node Training Package',
'tax-rate': -40.5,
price: 20
},
{
quantity: 1,
description: 'Angular crash course',
'tax-rate': -40.5,
price: 35
},
{
quantity: 1,
description: 'PHP Training',
'tax-rate': -40.5,
price: 35
}
]`
Now I want a desired output to be created for my invoice like
`[
{
quantity: 3,
description: 'Node Training Package',
'tax-rate': -40.5,
price: 20
},
{
quantity: 2,
description: 'Angular crash course',
'tax-rate': -40.5,
price: 35
},
{
quantity: 1,
description: 'PHP Training',
'tax-rate': -40.5,
price: 35
}
]`
I have used several functional but could not get my desired output. Please provide me a solution I will be thankful and every answer will be highly appreciated. Thanks.
I have tried using forEach but could not get desired output.