Skip to content

Commit af9b439

Browse files
authored
Create 1154-day-of-the-year.js
1 parent a5de337 commit af9b439

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

1154-day-of-the-year.js

+11
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)