I am dealing with timeseries data retrieved from an API that consists of random dates like the following:
[
{
"id": 1,
"score": 23,
"date": "2023-08-30"
},
{
"id": 2,
"score": 62,
"date": "2023-08-22"
},
{
"id": 3,
"score": 82,
"date": "2023-07-27"
}
.
.
.
]
My goal is to efficiently extract the data corresponding to the last day of each month. The desired output should look something like this:
[
{
"id": 1,
"score": 23,
"date": "2023-08-30"
},
{
"id": 3,
"score": 82,
"date": "2023-07-27"
}
.
.
.
]
To achieve this, I am currently experimenting with a function like the one below:
const getMonthlyData = (allData: Timeseries[]): Timeseries[] => {
//Iterate over each entry to identify the maximum date per month and include it in the return array
}
Restructured for clarity and better readability