Count digits in a factorial | Set 1 | This function receives an integer n , and returns the number of digits present in n ! ; factorial exists only for n >= 0 ; base case ; else iterate through n and calculate the value ; Driver code
function findDigits ( n ) { if ( n < 0 ) return 0 ; if ( n <= 1 ) return 1 ; let digits = 0 ; for ( let i = 2 ; i <= n ; i ++ ) digits += Math . log10 ( i ) ; return Math . floor ( digits ) + 1 ; } document . write ( findDigits ( 1 ) + " " ) ; document . write ( findDigits ( 5 ) + " " ) ; document . write ( findDigits ( 10 ) + " " ) ; document . write ( findDigits ( 120 ) + " " ) ;