forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetMonthDays.js
More file actions
Latest commit
38 lines (30 loc) · 796 Bytes
/
Copy pathGetMonthDays.js
File metadata and controls
38 lines (30 loc) · 796 Bytes
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
31
32
33
34
35
36
37
38
/**
function that takes month number and its year and returns the number of days within it
* @param monthNumber.
* @param year.
e.g.: mahfoudh.arous@gmail.com -> true
e.g.: mahfoudh.arous.com ->false
*/
import{isLeapYear}from'../Maths/LeapYear'
constgetMonthDays=(monthNumber,year)=>{
constthe31DaysMonths=[1,3,5,7,8,10,12]
constthe30DaysMonths=[4,6,9,11]
if(
!the31DaysMonths.includes(monthNumber)&&
!the30DaysMonths.includes(monthNumber)&&
monthNumber!==2
){
thrownewTypeError('Invalid Month Number.')
}
if(the31DaysMonths.includes(monthNumber)){
return31
}
if(the30DaysMonths.includes(monthNumber)){
return30
}
if(isLeapYear(year)){
return29
}
return28
}
export{getMonthDays}