We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a5de337 commit af9b439Copy full SHA for af9b439
1154-day-of-the-year.js
@@ -0,0 +1,11 @@
1
+/**
2
+ * @param {string} date
3
+ * @return {number}
4
+ */
5
+
6
+const dayOfYear = function(date) {
7
+ const [year, month, day] = date.split('-').map(s => +s),
8
+ months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
9
+ isLeapYear = !(year % 4) && month > 2 && (!!(year % 100) || !(year % 400))
10
+ return months.splice(0, month - 1).reduce((a, b) => a + b, day + +isLeapYear)
11
+}
0 commit comments