Generate number with given operation and check if it is palindrome | Function that returns true if str is a palindrome ; Function that returns true if the generated string is a palindrome ; sub contains N as a string ; Calculate the sum of the digits ; Repeat the substring until the length of the resultant string < sum ; If length of the resultant string exceeded sum then take substring from 0 to sum - 1 ; If the generated string is a palindrome ; Driver code
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len / 2 ; i ++ ) { if ( str [ i ] != str [ len - 1 - i ] ) return false ; } return true ; } function createStringAndCheckPalindrome ( N ) { let sub = " " + N , res_str = " " ; let sum = 0 ; while ( N > 0 ) { let digit = N % 10 ; sum += digit ; N = N / 10 ; } while ( res_str . length < sum ) res_str += sub ; if ( res_str . length > sum ) res_str = res_str . substring ( 0 , sum ) ; if ( isPalindrome ( res_str ) ) return true ; return false ; } let N = 10101 ; if ( createStringAndCheckPalindrome ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;