Deserium Number | Returns count of digits in n . ; Returns true if x is Diserium ; Compute powers of digits from right to left . ; If sum of powers is same as given number . ; Driver Code
function countDigits ( n ) { let c = 0 ; do { c ++ ; n = Math . floor ( n / 10 ) ; } while ( n != 0 ) ; return c ; } function isDeserium ( x ) { let temp = x ; let p = countDigits ( x ) ; let sum = 0 ; while ( x != 0 ) { let digit = x % 10 ; sum += Math . floor ( Math . pow ( digit , p ) ) ; p -- ; x = Math . floor ( x / 10 ) ; } return ( sum == temp ) ; } let x = 135 ; if ( isDeserium ( x ) ) document . write ( " " ) ; else document . write ( " " ) ;