-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDays_in_the_year.js
30 lines (18 loc) · 1.11 KB
/
Days_in_the_year.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ----------------------------------Description------------------------------
// 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:
// yearDays(2000) returns "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.
// ---------------------------------------------------------------------------
const yearDays = (year) => {
if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
return year + " has 366 days";
} else {
return year + " has 365 days";
}
}
console.log('result', yearDays(2000)) //result => 2000 has 366 days