Skip to content

Instantly share code, notes, and snippets.

/dates.js Secret

Created February 19, 2018 16:44
Show Gist options
  • Save anonymous/c1c5cc9302214dd0402032eec6ea5b2b to your computer and use it in GitHub Desktop.
Save anonymous/c1c5cc9302214dd0402032eec6ea5b2b to your computer and use it in GitHub Desktop.
const dates = ['Feb 22', 'Oct 30', 'Apr 13', 'Mar 16', 'Apr 28', 'July 11', 'Mar 15', 'Dec 5', 'Feb 9', 'Mar 29', 'Nov 2', 'Nov 24', 'Jan 7', 'Nov 23', 'Apr 23', 'Feb 12', 'Dec 29', 'Apr 27', 'Oct 4', 'Nov 19', 'Oct 5', 'Mar 18', 'Aug 20', 'Jan 29', 'Oct 27', 'Sep 15', 'Dec 28', 'Nov 2', 'July 4', 'Aug 10', 'Jan 30', 'May 8', 'Oct 14', 'May 29', 'Aug 27', 'Jan 9', 'July 14', 'Oct 1', 'Feb 6', 'June 12', 'Aug 19', 'July 6', 'Aug 4', 'June 14'];
const getDayNum = (d) => {
const now = new Date(d);
const start = new Date(now.getFullYear(), 0, 0);
const diff = now - start;
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
};
const totalDayNums = dates.map(getDayNum).reduce((acc, val) => acc + val);
const avg = totalDayNums / dates.length; // = 185
// July 4th!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment