Group and Aggregate an Array of Objects by Specified Keys

Implement a function that takes an array of objects and a list of keys, groups the objects by unique combinations of those key values, and aggregates numeric fields (sum, count, average) within each group. For example, grouping sales records by region and product and summing revenue. This is essentially a SQL GROUP BY in JavaScript — heavily tested at data-heavy product companies and companies that build analytics or reporting dashboards.

Examples
Input: []
Output:
Hints

Group and Aggregate an Array of Objects by Specified Keys

Implement a function that takes an array of objects and a list of keys, groups the objects by unique combinations of those key values, and aggregates numeric fields (sum, count, average) within each group. For example, grouping sales records by region and product and summing revenue. This is essentially a SQL GROUP BY in JavaScript — heavily tested at data-heavy product companies and companies that build analytics or reporting dashboards.