Smaller palindromic number closest to N | Function to check whether a number is palindrome or not ; Stores reverse of N ; Stores the value of N ; Calculate reverse of N ; Update rev ; Update N ; Update N ; if N is equal to rev of N ; Function to find the closest smaller palindromic number to N ; Calculate closest smaller palindromic number to N ; Update N ; Driver Code
function checkPalindrome ( N ) { let rev = 0 ; let temp = N ; while ( N != 0 ) { rev = Math . floor ( rev * 10 + N % 10 ) ; N = Math . floor ( N / 10 ) ; } N = temp ; if ( N == rev ) { return true ; } return false ; } function closestSmallerPalindrome ( N ) { do { N -- ; } while ( N >= 0 && ! checkPalindrome ( N ) ) ; return N ; } let N = 4000 ; document . write ( closestSmallerPalindrome ( N ) ) ;