Created
January 28, 2020 10:53
-
-
Save qodirovshohijahon/c1cd20dcb492f885d7809c0e8bb5ffc6 to your computer and use it in GitHub Desktop.
Subtract the Product and Sum of Digits of an Integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var subtractProductAndSum = function(n) { | |
if (n / 10 == 0) | |
return 0; | |
let mul = 1, sum = 0; | |
while( n != 0) { | |
mul *= n % 10; | |
sum += n % 10; | |
n = Math.trunc(n / 10); | |
} | |
return mul - sum; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was the most useful problem