My Typescript code includes a Map object called `stat_map` defined as
const stat_map: Map<string, IMonthlyStat[]> = new Map();
The interface IMonthlyStat is structured as shown below (Note that there are more fields in reality)
export interface IMonthlyStat {
month: string;
value: number;
}
The issue arises when the values within the Map, specifically the IMonthlyStat arrays, contain different month values due to data added at various times.
The format of the month field is '2021-02-01T00:00:00.000 UTC'.
I am looking for the most efficient way to standardize all IMonthlyStat arrays by removing initial elements so they all start with the same month string.
For example, if we have two IMonthlyStat arrays like
[
{month: '2021-02-01T00:00:00.000 UTC', value: 6},
{month: '2021-03-01T00:00:00.000 UTC', value: 8},
{month: '2021-04-01T00:00:00.000 UTC', value: 10}
]
and
[
{month: '2021-03-01T00:00:00.000 UTC', value: 7},
{month: '2021-04-01T00:00:00.000 UTC', value: 9}
]
How can I achieve results like this:
[
{month: '2021-03-01T00:00:00.000 UTC', value: 8},
{month: '2021-04-01T00:00:00.000 UTC', value: 10}
]
and
[
{month: '2021-03-01T00:00:00.000 UTC', value: 7},
{month: '2021-04-01T00:00:00.000 UTC', value: 9}
]