I have below Object with me.
car = [{
Acc: "X1",
primary: true,
Name: "Park Street",
Date: "2018/01/01"
},{
Acc: "X1",
primary: false,
Name: "Park Street 2",
Date: "2018/03/01"
},{
Acc: "X2",
primary: false,
Name: "Park Street 3",
Date: "2018/01/01"
},{
Acc: "X2",
primary: false,
Name: "Park Street 4",
Date: "2018/05/01"
}];
I have to get only one element from each group of "Acc". One element for each of Acc:"X1" and Acc:"X2". Logic to find that should be if primary: true, then select that element from the group else pick the one having latest Date: value.
I do understand this requirement can be achievable using underscore js but I am new in this and can't figure out the relevant way.
Can someone please help me here?