Smallest number to be subtracted to convert given number to a palindrome | Function to evaluate minimum subtraction required to make a number palindrome ; Counts number of subtractions required ; Run a loop till N >= 0 ; Store the current number ; Store reverse of current number ; Reverse the number ; Check if N is palindrome ; Increment the counter ; Reduce the number by 1 ; Print the result ; Driver Code ; Function call
function minSub ( N ) { let count = 0 ; while ( N >= 0 ) { let num = N ; let rev = 0 ; while ( num != 0 ) { let digit = num % 10 ; rev = ( rev * 10 ) + digit ; num = Math . floor ( num / 10 ) ; } if ( N == rev ) { break ; } count ++ ; N -- ; } document . write ( count ) ; } let N = 3456 ; minSub ( N ) ;