I recently obtained weather forecast data from an API, which can be accessed here: Weather Forecast Data
This dataset includes weather predictions for 5 days, with updates every 3 hours. My goal is to organize the data by date and determine the minimum and maximum temperatures for each day.
The desired output format is as follows:
[
{
"date" : "2021/7/2",
"min_temp": 282.06,
"max_temp": 300.05
},
{
"date" : "2021/8/2",
"min_temp": 282.06,
"max_temp": 300.05
},
{
"date" : "2021/9/2",
"min_temp": 282.06,
"max_temp": 300.05
},
{
"date" : "2021/10/2",
"min_temp": 282.06,
"max_temp": 300.05
},
{
"date" : "2021/11/2",
"min_temp": 282.06,
"max_temp": 300.05
},
]
I have attempted to group the dates using the following code:
var result = [];
newArray.reduce(function (res, value) {
if (!res[value.dt_txt]) {
res[value.dt_txt] = { dt_txt: value.dt_txt, value };
result.push(res[value.dt_txt])
}
return res;
}, {});
However, this code only groups the dates and does not calculate the min/max values for each day. I am currently looking for a solution to address this issue.