Largest palindrome not exceeding N which can be expressed as product of two 3 | Function to find the largest palindrome not exceeding N which can be expressed as the product of two 3 - digit numbers ; Stores all palindromes ; Stores the product ; Check if X is palindrome ; Check n is less than N ; If true , append it in the list ; Print the largest palindrome ; Driver Code ; Function Call
function palindrome_prod ( N ) { var palindrome_list = [ ] ; var i , j ; for ( i = 101 ; i < 1000 ; i ++ ) { for ( j = 121 ; j < 1000 ; j += ( i % 11 == 0 ) ? 1 : 11 ) { var n = i * j ; var x = n . toString ( ) ; var y = x ; y = y . split ( " " ) . reverse ( ) . join ( " " ) ; if ( x == y ) { if ( n < Number ( N ) ) { palindrome_list . push ( i * j ) ; } } } } document . write ( Math . max . apply ( null , palindrome_list ) ) ; } var N = " " ; palindrome_prod ( N ) ;