I have array of objects
const data=[
{typeId: 1, sort: 1, name: "Test1"},
{typeId: 2, sort: 1, name: "Test2"},
{typeId: 1, sort: 2, name: "Test3"},
{typeId: 3, sort: 1, name: "Test4"},
];
I want to remove duplicates by key "typeId" and key "sort" value is bigger. And i want add key "count" - how many times object duplicate by typeId.
This is what I want to achieve:
const answer=[
{typeId: 1, sort: 1, name: "Test1", count: 2},
{typeId: 2, sort: 1, name: "Test2", count: 1},
{typeId: 3, sort: 1, name: "Test4", count: 1},
];
How can I do that?