Hope this helps you. Code should be self explanatory. Please let me know.
function isLeapYear(year) {
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}
function getMonthLength(month, year) {
switch(month) {
case "Apr": case "Jun": case "Sep": case "Nov":
return 30;
case "Feb":
return isLeapYear(year) ? 29 : 28;
default:
return 31;
}
}
console.log(getMonthLength('Feb', 2000));
console.log(getMonthLength('Jan', 2001));
console.log(getMonthLength('Feb', 2001));
console.log(getMonthLength('Sep', 2001));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…