-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathleapYear.js
22 lines (14 loc) · 819 Bytes
/
leapYear.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
A variation of determining leap years, assuming only integers are used and years can be negative and positive.
Write a function which will return the days in the year and the year entered in a string. For example 2000, entered as an integer, will return as a string 2000 has 366 days
There are a few assumptions we will accept the year 0, even though there is no year 0 in the Gregorian Calendar.
Also the basic rule for validating a leap year are as follows
Most years that can be divided evenly by 4 are leap years.
Exception: Century years are NOT leap years UNLESS they can be evenly divided by 400.
So the years 0, -64 and 2016 will return 366 days. Whilst 1974, -10 and 666 will return 365 days.
*/
//Answer//
function yearDays(y)
{
return !(y%4)&&y%100||!(y%400)?y+' has 366 days':y+' has 365 days'
}