Count the occurrence of digit K in a given number N using Recursion | Function to count the digit K in the given number N ; Extracting least significant digit ; Driver Code
function countdigits ( n , k ) { if ( n == 0 ) return 0 ; var digit = n % 10 ; if ( digit == k ) return 1 + countdigits ( n / 10 , k ) ; return countdigits ( n / 10 , k ) ; } var n = 1000 ; var k = 0 ; document . write ( countdigits ( n , k ) ) ;