Count numbers from a given range that contains a given number as the suffix | Function to count the number ends with given number in range ; Find number of digits in A ; Find the power of 10 ; Incrementing the A ; Driver code ; Function Call
function countNumEnds ( A , L , R ) { let temp = 0 , count = 0 , digits = 0 ; let cycle = 0 ; digits = Math . round ( Math . log10 ( A ) ) + 1 ; temp = Math . round ( Math . pow ( 10 , digits ) ) ; cycle = temp ; while ( temp <= R ) { if ( temp >= L ) count ++ ; temp += cycle ; } document . write ( count ) ; } let A = 2 , L = 2 , R = 20 ; countNumEnds ( A , L , R ) ;