I need to extract N items from each group within a list using Typescript. In C# with LINQ, I would achieve something similar like this but I am unsure of the equivalent in TypeScript.
var rr = db.Products.GroupBy(x => x.ProductSubTypeCategoryId).Select(g => new { GroupName = g.Key, Items = g.Take(4).ToList() });
My model is
const lstTrade : Trade [] = [
{ contractName: 'Contract1' ,amount : 12},
{ contractName: 'Contract1' ,amount : 12},
{ contractName: 'Contract1' ,amount : 20},
{ contractName: 'Contract2' ,amount : 20},
{ contractName: 'Contract2' ,amount : 20},
{ contractName: 'Contract2' ,amount : 20}
];
Now, I have a list of Trade items and my goal is to retrieve only 2 items from the list with unique contract names. Specifically, two items with "Contract1" and two items with "Contract2".