The 19th Project Euler problem - Counting Sundays - is stated as follows. How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
// Get all the months between Jan 1901 to Dec 2000.
// We add 12 since we want the months in 2000 as well.
const months = (2000 - 1901) * 12 + 12;
// Iterate one month at a time.
const sundays = Array.from({length:months})
.filter((_,month) => {
const currentYear = 1901 + Math.floor(month/12);
const currentMonth = month % 12;
// Check the weekday of the 1 in the current year and month.
// 0 equals Sunday.
return new Date(currentYear, currentMonth, 1).getDay() === 0
}).length;