Find the number of times every day occurs in a month | function to find occurrences ; stores days in a week ; Initialize all counts as 4. ; find index of the first day ; number of days whose occurrence will be 5 ; mark the occurrence to be 5 of n - 28 days ; print the days ; Driver code
function occurrenceDays ( n , firstday ) { let days = [ " " , " " , " " , " " , " " , " " , " " ] ; let count = [ ] ; for ( let i = 0 ; i < 7 ; i ++ ) count [ i ] = 4 ; let pos = 0 ; for ( let i = 0 ; i < 7 ; i ++ ) { if ( firstday == days [ i ] ) { pos = i ; break ; } } let inc = n - 28 ; for ( let i = pos ; i < pos + inc ; i ++ ) { if ( i > 6 ) count [ i % 7 ] = 5 ; else count [ i ] = 5 ; } for ( let i = 0 ; i < 7 ; i ++ ) { document . write ( days [ i ] + " " + count [ i ] + " " ) ; } } let n = 31 ; let firstday = " " ; occurrenceDays ( n , firstday ) ;