Arcy Arcy - 12 days ago 7
Javascript Question

Check if days in month are weekends

In this function I'm trying to check if days of a month are weekends or not. First I push all days in an array, then I push in another array every item =! 0 or 6, that are weekend days number. But if I read console log, my businessDays array contains all the days, not only business day.

getDaysArrayByMonth(year, month) {
let numberOfDays = moment([year, month], "YYYY-MM LT").daysInMonth();
const arrDays = [];
const businessDays = [];
while (numberOfDays) {
const current = moment().date(numberOfDays);
arrDays.push(current);
numberOfDays--;
}

arrDays.forEach(item => {
if (item.days() != 0 || item.days() != 6){
businessDays.push(item)
}
});

return businessDays;
}

getDayArrayByMonth(2016, 11);

Answer

if statement is not correct

arrDays.forEach(item => {
   if (item.days() != 0 && item.days() != 6){
       businessDays.push(item)
   }
});