text: Count n digit numbers not having a particular digit | JavaScript Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) / 2 digits ; Calling digitNumber function with n / 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Initializing variables
code: const mod = 1000000007 ; function digitNumber ( n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 9 ; if ( n % 2 ) { let temp = digitNumber ( ( n - 1 ) / 2 ) % mod ; return ( 9 * ( temp * temp ) % mod ) % mod ; } else { let temp = digitNumber ( n / 2 ) % mod ; return ( temp * temp ) % mod ; } } function countExcluding ( n , d ) { if ( d == 0 ) return ( 9 * digitNumber ( n - 1 ) ) % mod ; else return ( 8 * digitNumber ( n - 1 ) ) % mod ; } let d = 9 ; let n = 3 ; document . write ( countExcluding ( n , d ) + " " ) ;