You are viewing a single comment's thread. Return to all comments →
Not doing anything fancy with the special 1918 case
OOP approach
function dayOfProgrammer(year) { if (year === 1918) return '26.09.1918'; const calendar = createCalendar(year); return calendar.dayOfTheProgrammer(); } function createCalendar(year) { if (1700 <= year && year <= 1917) return (new Julian(year)); if (1919 <= year) return (new Gregorian(year)); } function Julian(year) { this.year = year; this.leapYear = function() { return (this.year % 4 === 0); } this.dayOfTheProgrammer = function() { return (this.leapYear()) ? ('12.09.' + this.year) : ('13.09.' + this.year) } } function Gregorian(year) { this.year = year; this.leapYear = function() { return (this.year % 400 === 0 || (this.year % 4 === 0 && this.year % 100 !== 0)); } this.dayOfTheProgrammer = function() { return (this.leapYear()) ? ('12.09.' + this.year) : ('13.09.' + this.year) } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day of the Programmer
You are viewing a single comment's thread. Return to all comments →
Not doing anything fancy with the special 1918 case
OOP approach