I got an array, which contains dates (formatted as dates, not strings) within a specified range:
var dates = function(startDate, endDate) {
var dates = [],
currentDate = startDate,
addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
};
while (currentDate <= endDate) {
dates.push(currentDate);
currentDate = addDays.call(currentDate, 1);
}
return dates;
};
var startDate = new Date("2019-04-01");
var endDate = new Date("2019-04-26");
var dates = dates(startDate, endDate);
Then I filtered out the weekends like this:
var workingDays = dates.filter(function(e, index){
return (e.getDay() != 0 && e.getDay() != 6);
});
That worked perfectly so far, but my problem is that I need to filter out holidays aswell. I tried to use the same filter function as for the weekends, like this:
var holidays = [new Date("2019-04-19"), new Date("2019-04-22")];
var workingDays = dates.filter(function(e, index){
return (e.getDay() != 0 && e.getDay() != 6 && e != holidays);
});
That didn't work tho and just returned the same array as before.
Does anyone know how I can achieve this and just filter out the specified dates in the variable?
Array.prototype.some()