Narcissistic number | Function to count digits ; Returns true if n is Narcissistic number ; count the number of digits ; calculates the sum of digits raised to power ; Driver Code
function countDigit ( n ) { if ( n == 0 ) return 0 ; return ( 1 + countDigit ( n / 10 ) ) ; } function check ( n ) { let l = countDigit ( n ) ; let dup = n ; let sum = 0 ; while ( dup ) { sum += Math . pow ( dup % 10 , l ) ; dup = parseINT ( dup / 10 ) ; } return ( n == sum ) ; } let n = 1634 ; if ( check ( ! n ) ) document . write ( " " ) ; else document . write ( " " ) ;