Skip to content

Instantly share code, notes, and snippets.

@theer1k
Last active April 12, 2022 13:07
Show Gist options
  • Save theer1k/e987949556a41a4687c27d7076de435c to your computer and use it in GitHub Desktop.
Save theer1k/e987949556a41a4687c27d7076de435c to your computer and use it in GitHub Desktop.
[Javascript] Most Frequent Days
const mostFrequentDays = year => {
let dayName = d => d.toLocaleString('en',{ weekday:'long' });
let firstDay = new Date(year, 0, 1);
let day = dayName(firstDay);
let lastDay = dayName(new Date(year, 11, 31));
let daysResult = day == lastDay? [day] : [day, lastDay];
return firstDay.getDay() ? daysResult : daysResult.reverse();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment