Narcissistic number | Javascript program for checking of Narcissistic number ; Traversing through the string ; Since ascii value of numbers starts from 48 so we subtract it from sum ; Converting string to integer ; Comparing number and sum ; Driver Code
function getResult ( st ) { let sum = 0 ; let length = st . length ; for ( let i = 0 ; i < length ; i ++ ) { sum = sum + Math . pow ( st [ i ] - ' ' , length ) ; } let number = parseInt ( st , 10 ) ; if ( number == sum ) return " " ; else return " " ; } let st = " " ; document . write ( getResult ( st ) ) ;