N 'th palindrome of K digits | Utility function to reverse the number n ; Boolean Function to check for palindromic number ; Function for finding nth palindrome of k digits ; Get the smallest k digit number ; check the number is palindrom or not ; if n 'th palindrome found  break the loop ; Increment number for checking next palindrome ; Driver code
function reverseNum ( n ) { let rem , rev = 0 ; while ( n > 0 ) { rem = n % 10 ; rev = rev * 10 + rem ; n = parseInt ( n / 10 ) ; } return rev ; } function isPalindrom ( num ) { return num == reverseNum ( num ) ; } function nthPalindrome ( n , k ) { let num = Math . pow ( 10 , k - 1 ) ; while ( true ) { if ( isPalindrom ( num ) ) -- n ; if ( n == 0 ) break ; ++ num ; } return num ; } let n = 6 , k = 5 ; document . write ( n + " " + k + " " + nthPalindrome ( n , k ) + " " ) ; n = 10 ; k = 6 ; document . write ( n + " " + k + " " + nthPalindrome ( n , k ) ) ;