Sum of all palindrome numbers present in an Array | Function to reverse a number n ; Function to check if a number n is palindrome ; If n is equal to the reverse of n it is a palindrome ; Function to calculate sum of all array elements which are palindrome ; Summation of all palindrome numbers present in array ; Driver Code
function reverse ( n ) { let d = 0 , s = 0 ; while ( n > 0 ) { d = n % 10 ; s = s * 10 + d ; n = Math . floor ( n / 10 ) ; } return s ; } function isPalin ( n ) { return n == reverse ( n ) ; } function sumOfArray ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] > 10 ) && isPalin ( arr [ i ] ) ) { s += arr [ i ] ; } } return s ; } let n = 6 ; let arr = [ 12 , 313 , 11 , 44 , 9 , 1 ] ; document . write ( sumOfArray ( arr , n ) ) ;