MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / getMonthDays

Function getMonthDays

Timing-Functions/GetMonthDays.js:11–36  ·  view source on GitHub ↗
(monthNumber, year)

Source from the content-addressed store, hash-verified

9import { isLeapYear } from '../Maths/LeapYear'
10
11const getMonthDays = (monthNumber, year) => {
12 const the31DaysMonths = [1, 3, 5, 7, 8, 10, 12]
13 const the30DaysMonths = [4, 6, 9, 11]
14
15 if (
16 !the31DaysMonths.includes(monthNumber) &&
17 !the30DaysMonths.includes(monthNumber) &&
18 monthNumber !== 2
19 ) {
20 throw new TypeError('Invalid Month Number.')
21 }
22
23 if (the31DaysMonths.includes(monthNumber)) {
24 return 31
25 }
26
27 if (the30DaysMonths.includes(monthNumber)) {
28 return 30
29 }
30
31 if (isLeapYear(year)) {
32 return 29
33 }
34
35 return 28
36}
37
38export { getMonthDays }

Callers 2

checkDateFunction · 0.90

Calls 1

isLeapYearFunction · 0.90

Tested by

no test coverage detected