` ````
function monthDays(){
var monthSelect = $('#month.stepper select');
var monthValue = parseInt(monthSelect.val());
var days30 = [4, 6, 9, 11];
if(monthValue == 2){
//determine the number of days for february (leap year)
var yearValue = parseInt($('#year.stepper select').val());
var dayAmount = !(yearValue & 3 || !(yearValue % 25) && yearValue & 15) ? 29 : 28;
} else if(days30.indexOf(monthValue) >= 0){
var dayAmount = 30;
} else {
var dayAmount = 31;
};
return dayAmount;
};
```

All this function is trying to do is return the number of days given a month and year. I ended up rewriting this recently as the following:

` ````
var days = !isNaN(month) && !isNaN(year)
? new Date(parseInt(year), parseInt(month) + 1, 0).getDate()
: 31;
```

That's it. If I have a month and year, just give me the days for it. Granted the first attempt is super-verbose, it works exactly how it would in my head thinking about each case (months that don't have 31 days, checking for February specifically, then leap years). At least I figure I must be getting more clever?

]]>