Count the number of digits of palindrome numbers in an array | Function to return the reverse of n ; Function that returns true if n is a palindrome ; Function to return the count of digits of n ; Function to return the count of digits in all the palindromic numbers of arr [ ] ; If arr [ i ] is a one digit number or it is a palindrome ; Driver code
function reverse ( n ) { let rev = 0 ; while ( n > 0 ) { let d = n % 10 ; rev = rev * 10 + d ; n = parseInt ( n / 10 ) ; } return rev ; } function isPalin ( n ) { return ( n == reverse ( n ) ) ; } function countDigits ( n ) { let c = 0 ; while ( n > 0 ) { n = parseInt ( n / 10 ) ; c ++ ; } return c ; } function countPalinDigits ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 10 || isPalin ( arr [ i ] ) ) { s += countDigits ( arr [ i ] ) ; } } return s ; } let arr = [ 121 , 56 , 434 ] ; let n = arr . length ; document . write ( countPalinDigits ( arr , n ) ) ;