DEV Community

Discussion on: Daily Challenge #27 - Unlucky Days

Collapse
 
alvaromontoro profile image
Alvaro Montoro • Edited

JavaScript

const unluckyDays = year => {
  let unlucky = 0;
  for (x = 0; x < 12; x++) {
    unlucky += new Date(year, x, 13).getDay() === 5 ? 1 : 0;
  }
  return unlucky;
}
Enter fullscreen mode Exit fullscreen mode

Live demo on CodePen

Collapse
 
wheatup profile image
Hao

Brilliant solution, very simple and effective. Although I think ? 1 : 0 is not necessary :p

Collapse
 
alvaromontoro profile image
Alvaro Montoro

Yes. It's not really necessary because true is turn into 1, and false to 0. I have a second version using that and a reducer in the demo.