Objective
If given a month-end in Date format and a frequency,
return a list which includes the given month-end and the 11 preceding month-ends by frequency.
Frequency/
duration is month based (E.g. duration of 2 is every 2 months and
length species the number of results to return in the list-->
Given
Month-end: '04/30/2022' or given the year and month find the month-end(E.g. Year = 2022 and month = 4 like code below)
Duration: '2'
Length: 3
Expected
Output: ['04/302022', '02/28/2022', '12/31/2021']
const makeDates = (startYear, startMonth, duration = 1, length = 3) =>
Array.from({ length }, (_, index) =>
new Date(startYear, startMonth - index * duration, 0)
.toLocaleDateString("en-US")
.split("/")
.map((v) => v.padStart(2, 0))
.join("/")
);
console.log(makeDates(2022, 4, 2));
What I have tried:
My code is very complex and not working in Python. I'm trying to do the above in python but only have a javascrpit implementation.