function isAGoodDay (date) {
var weekOfMonth = Math.floor(date.getDate() / 7) + 1;
var dayOfWeek = date.getDay();
var day = days[dayOfWeek];
if (day === '') return false;
return availability['week'+weekOfMonth][day];
}
function listGoodDays(year, month) {
var lastDay = new Date(new Date(year, month, 1)-1).getDate();
return listOfdays[lastDay]
.filter((d) => (isAGoodDay(new Date(year, month-1, d))))
.map((d) => (new Date(year, month-1, d)));
}
const availability = {
week1: {
mon: false,
tue: true,
wed: true,
thu: true,
fri: false,
},
week2: {
mon: false,
tue: true,
wed: true,
thu: true,
fri: false,
},
week3: {
mon: false,
tue: true,
wed: true,
thu: true,
fri: false,
},
week4: {
mon: false,
tue: true,
wed: true,
thu: true,
fri: false,
},
week5: {
mon: false,
tue: true,
wed: true,
thu: true,
fri: false,
}
};
var days = ['','mon','tue','wed','thu','fri',''];
var listOfdays =
{"28" : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]
,"29" : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
,"30" : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
,"31" : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
};
console.log( listGoodDays(2018, 11) );