Dudeney Numbers | Function that returns true if n is a Dudeney number ; If n is not a perfect cube ; Last digit ; Update the digit sum ; Remove the last digit ; If cube root of n is not equal to the sum of its digits ; Driver code
function isDudeney ( n ) { let cube_rt = parseInt ( Math . round ( ( Math . pow ( n , 1.0 / 3.0 ) ) ) ) ; if ( cube_rt * cube_rt * cube_rt != n ) return false ; let dig_sum = 0 ; let temp = n ; while ( temp > 0 ) { let rem = temp % 10 ; dig_sum += rem ; temp = parseInt ( temp / 10 ) ; } if ( cube_rt != dig_sum ) return false ; return true ; } let n = 17576 ; if ( isDudeney ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;