Finding sum of digits of a number until sum becomes single digit | Driver code
function digSum ( n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } n = 9999 ; document . write ( digSum ( n ) ) ;