← Back to challenges

Day Number of Year

JavaScriptHarddatesformattingnumbersstrings

Instructions

Each year has 365 or 366 days. Given a string date representing a Gregorian calendar date formatted as month/day/year, return the day-number of the year.

Examples

dayOfYear("12/13/2020") ➞ 348

dayOfYear("12/17/2020") ➞ 352

dayOfYear("11/16/2020") ➞ 321

dayOfYear("1/9/2019") ➞ 9

dayOfYear("3/1/2004") ➞ 61

dayOfYear("12/31/2000") ➞ 366

Notes

All input strings in the tests are valid dates.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.