Can you suggest the most efficient method to group by multiple keys and calculate the sum of multiple property values in a JavaScript array?
For example:
[
{ Category: "Category 1", Subcategory: "Subcategory 1", Value1: "15", Value2: "5" },
{ Category: "Category 1", Subcategory: "Subcategory 2", Value1: "20", Value2: "10" },
{ Category: "Category 2", Subcategory: "Subcategory 1", Value1: "25", Value2: "15" },
{ Category: "Category 2", Subcategory: "Subcategory 2", Value1: "30", Value2: "20" },
{ Category: "Category 1", Subcategory: "Subcategory 1", Value1: "35", Value2: "25" },
{ Category: "Category 1", Subcategory: "Subcategory 2", Value1: "40", Value2: "30" },
{ Category: "Category 2", Subcategory: "Subcategory 1", Value1: "45", Value2: "35" },
{ Category: "Category 2", Subcategory: "Subcategory 2", Value1: "50", Value2: "40" }
]
Desired Result
[
{ Category: "Category 1", Subcategory: "Subcategory 1", Value1: "50", Value2: "30" },
{ Category: "Category 1", Subcategory: "Subcategory 2", Value1: "60", Value2: "40" },
{ Category: "Category 2", Subcategory: "Subcategory 1", Value1: "70", Value2: "50" },
{ Category: "Category 2", Subcategory: "Subcategory 2", Value1: "80", Value2: "60" }
]