|
||||||||||||||||||||||||||
JS Tutorial
part i - JS language
Part ii - JS objects
Part ii - Client-Side JS
JS Articles |
JavaScript Frequently Ask Question How to determine the leap year? by Puthyrak Kang June 28, 2009A leap year (or intercalary year) is a year containing one or more extra days (or, in the case of lunisolar calendars, an extra month) in order to keep the calendar year synchronized with the astronomical or seasonal year. February in a leap year has 29 days instead of the usual 28 so the year lasts 366 days instead of the usual 365. Algorithmif year modulo 400 is 0 then leap else if year modulo 100 is 0 then no_leap else if year modulo 4 is 0 then leap else no_leap Code
<script text="text/javascript">
function isLeap(year){
if(year % 400 == 0){
return true;
}
if(year % 100 == 0){
return false;
}
if(year % 4 == 0){
return true;
}
return false;
}
</script>
|
References(1) Aland Shalloway & James R. Trott, Design Patterns Explained, Second Edition.(2) Allen Holub, Holub on Patterns, Learning Design Patterns by Looking at Code (3) Eric Evans, Domain-Driven Design, Tackling complexity in the heart of software. Advertisement |
||||||||||||||||||||||||
|
||||||||||||||||||||||||||