mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
refactor: use isLeapYear
(#1638)
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
e.g.: mahfoudh.arous.com ->false
|
||||
*/
|
||||
|
||||
import { isLeapYear } from '../Maths/LeapYear'
|
||||
|
||||
const getMonthDays = (monthNumber, year) => {
|
||||
const the31DaysMonths = [1, 3, 5, 7, 8, 10, 12]
|
||||
const the30DaysMonths = [4, 6, 9, 11]
|
||||
@ -26,11 +28,8 @@ const getMonthDays = (monthNumber, year) => {
|
||||
return 30
|
||||
}
|
||||
|
||||
// Check for Leap year
|
||||
if (year % 4 === 0) {
|
||||
if (year % 100 !== 0 || (year % 100 === 0 && year % 400 === 0)) {
|
||||
return 29
|
||||
}
|
||||
if (isLeapYear(year)) {
|
||||
return 29
|
||||
}
|
||||
|
||||
return 28
|
||||
|
Reference in New Issue
Block a user