I have an array of information structured like this:
0: { first: "sea", second: "deniz", languageId: "English-Turkish"}
1: { first: "play", second: "oynamak", languageId: "English-Turkish"}
2: { first: "swim", second: "yuzmek", languageId: "English-Turkish"}
3: { first: "foo", second: "bar", languageId: "German-Russian"}
4: { first: "computer", second: "l'ordi", languageId: "English-French"}
My goal is to group them by languageId
and count the items in each group. To help with this, I have an object defined as follows:
export class stats{
name: String;
count: number;
}
The desired output should be:
0: { name: "English-Turkish", count: 3 }
1: { name: "German-Russian", count: 1 }
2: { name: "English-French", count: 1 }
I think using the Array.reduce function would be a good approach for this task, but I'm struggling to implement it. Can you provide guidance on how to achieve this?