Last active
September 20, 2017 14:31
-
-
Save ezamelczyk/fc6f83a9fab86c0befbf1cd04347dbd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const readInterface = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function getLastMondayMonths(startYear, endYear) { | |
if(!endYear) { | |
endYear = startYear; | |
} | |
if (startYear > endYear) { | |
console.log("Starting year must be smaller or equal to the ending year.\n"); | |
} else { | |
let date = new Date(startYear, 1, 0); | |
let dates = ""; | |
while (date.getFullYear() <= endYear) { | |
for(let month = 1; month <= 12; month++){ | |
let tempDate = new Date(date.getFullYear(), month, 0); | |
if(tempDate.getDay() === 1) { | |
dates += " " + (tempDate.getMonth() + 1) + "/" + tempDate.getDate() + "/" + tempDate.getFullYear(); | |
} | |
} | |
date.setFullYear(date.getFullYear() + 1); | |
} | |
return dates.substr(1); | |
} | |
} | |
readInterface.question("Type starting year: ", (year) => { | |
readInterface.question("Type ending year: ", (end) => { | |
console.log(getLastMondayMonths(year, end)); | |
process.exit(); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment