I have an object which contains number of kilograms and some dates. What I am trying to do is to push the rows with unique dates to a new array. If there is rows containing the same date, only the one with the the highest kilogram should be pushed to the new array. If there is two dates with the same kg, only one should be chosen.
Heres how it looks like:
[{"kg":10,"date":"14/10/2019"},
{"kg":15,"date":"14/10/2019"},
{"kg":15,"date":"14/10/2019"},
{"kg":5,"date":"15/10/2019"},
{"kg":10,"date":"16/10/2019"}]
And here is how the result should be in the new array:
{"kg":15,"date":"14/10/2019"},
{"kg":5,"date":"15/10/2019"},
{"kg":10,"date":"16/10/2019"}]
Now I cant figure out how to check the kg and get the highest ones. I know that I can use "Math.max" to get the highest, but not how to use it just for the same dates. I have been trying with some foreach loops but I cant understand how I can group the dates and do the Math.max. I really need some guidance here.
Note: the language is Javascript.