Count of Leap Years in a given year range | Function to calculate the number of leap years in range of ( 1 , year ) ; Function to calculate the number of leap years in given range ; Driver Code
function calNum ( year ) { return parseInt ( year / 4 , 10 ) - parseInt ( year / 100 , 10 ) + parseInt ( year / 400 , 10 ) ; } function leapNum ( l , r ) { l -- ; let num1 = calNum ( r ) ; let num2 = calNum ( l ) ; document . write ( ( num1 - num2 ) + " " ) ; } let l1 = 1 , r1 = 400 ; leapNum ( l1 , r1 ) ; let l2 = 400 , r2 = 2000 ; leapNum ( l2 , r2 ) ;