I have an array Order[], where Order is:
interface Order {
orderId: number;
productName: string;
color: string;
quantity: number;
price: number;
link: string;
}
I want to create a mapping where:
- key is (productName, color)
- values are quantity, price, link. Quantity and price are a sum of matching properties of original objects. link is the same for all so can just keep one of them.
I know how to create a single item using filter and reduce, similar to this question: How to sum values in typescript array based on array items property?
I tried to use a Map object, but got stuck because I couldn't compare the keys properly - always got false