Check if the sum of digits of number is divisible by all of its digits | JavaScript implementation of above approach ; Converting integer to string ; Initialising sum to 0 ; Traversing through the string ; Converting character to int ; Comparing number and sum Traversing again ; Check if any digit is not dividing the sum ; Return false ; If any value is not returned then all the digits are dividing the sum SO return true ; Driver Code ; passing this number to get result function
function getResult ( n ) { var st = n . toString ( ) ; var sum = 0 var length = st . length ; for ( var i = 0 ; i < st . length ; i ++ ) { sum = sum + Number ( st [ i ] ) } for ( var i = 0 ; i < st . length ; i ++ ) { if ( sum % Number ( st [ i ] ) != 0 ) { return ' ' } else { return ' ' ; } } } var n = 123 ; document . write ( getResult ( n ) ) ;