function getDateOfNDaysAgo(days, date = new Date()) {
const dateAgo = new Date(date.getTime());
dateAgo.setDate(date.getDate() - days);
return dateAgo;
}
console.log(getDateOfNDaysAgo(5, new Date('2022-04-10')).toDateString());
/*
run:
"Tue Apr 05 2022"
*/