Self Numbers | Function to find the sum of digits of a number N ; Function to check for Self number ; Driver code
function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = parseInt ( n / 10 ) ; } return sum ; } function isSelfNum ( n ) { for ( let m = 1 ; m <= n ; m ++ ) { if ( m + getSum ( m ) == n ) return false ; } return true ; } let n = 20 ; if ( isSelfNum ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }