Recursive sum of digits of a number formed by repeated appends | Return single digit sum of a number . ; Returns recursive sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; Driver Code
function digSum ( n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } function repeatedNumberSum ( n , x ) { sum = x * digSum ( n ) ; return digSum ( sum ) ; } let n = 24 ; let x = 3 ; document . write ( repeatedNumberSum ( n , x ) ) ;