Count all numbers up to N having M as the last digit | Function to count the numbers ending with M ; Stores the count of numbers required ; Calculate count upto nearest power of 10 ; Computing the value of x ; Adding the count of numbers ending at M from x to N ; Driver Code ; Function call
function getCount ( N , M ) { let total_count = 0 total_count += Math . floor ( N / 10 ) let x = Math . floor ( N / 10 ) * 10 if ( ( N - x ) >= M ) { total_count = total_count + 1 } return total_count } let N = 100 let M = 1 document . write ( getCount ( N , M ) )