function countDaysOfWeekInRange(startDateStr, endDateStr, daysOfWeek) {
const startDate = new Date(startDateStr);
const endDate = new Date(endDateStr);
let count = 0;
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
const dayOfWeek = currentDate.getDay();
if (daysOfWeek.includes(dayOfWeek)) {
count++;
}
currentDate.setDate(currentDate.getDate() + 1);
}
return count;
}
const startDate = "2024-09-04 14:12:21";
const endDate = "2024-09-11 14:12:21";
const targetDays = [2, 3, 5, 6];
console.log(countDaysOfWeekInRange(startDate, endDate, targetDays));