Program to print all palindromes in a given range | A function to check if n is palindrome ; Find reverse of n ; If n and rev are same , then n is palindrome ; prints palindrome between min and max ; Driver program to test above function
function isPalindrome ( n ) { var rev = 0 ; for ( var i = n ; Math . trunc ( i ) > 0 ; i /= 10 ) { rev = ( ( rev * 10 ) + ( Math . trunc ( i ) % 10 ) ) ; } return ( n == rev ) ; } function countPal ( min , max ) { for ( var i = min ; i <= max ; i ++ ) { if ( isPalindrome ( i ) ) document . write ( i + " " ) ; } } countPal ( 100 , 2000 ) ;