DEV Community

Discussion on: Daily Challenge #27 - Unlucky Days

Collapse
 
hoffmann profile image
Peter Hoffmann

Javascript:

function unluckyDays(year) {
    return [[2, 1, 3, 1, 1, 2, 2], [1, 2, 2, 1, 1, 3, 2]]
    [+(year % 400 === 0 || year % 4 === 0 && year % 100 > 0)]
    [new Date(year, 0, 13).getDay()]
}

You can determine the number of Fridays in a given year as the number of days between the 13th of one and the next month is fixed. All you need to know is the day of January 13th and whether the year is a leap-year.