How should I remove duplicate objects with the condition?
suppose I have this array :
let my_array = [
{ name: "foo", version: "10" },
{ name: "foo", version: "60" },
{ name: "foo", version: "20" },
{ name: "bar", version: "400" },
];
I need to keep the object that has latest version in it from duplicates.
I know I can use Set for removing dups :
let unique = my_array.filter((set => f =>
!set.has(f.name) && set.add(f.name)
)
(new Set)
)
the expected result with condition of max version is :
let my_array = [
{ name: "foo", version: "60" },
{ name: "bar", version: "400" },
];