Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save qodirovshohijahon/c1cd20dcb492f885d7809c0e8bb5ffc6 to your computer and use it in GitHub Desktop.
Save qodirovshohijahon/c1cd20dcb492f885d7809c0e8bb5ffc6 to your computer and use it in GitHub Desktop.
Subtract the Product and Sum of Digits of an Integer
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;
};
@qodirovshohijahon
Copy link
Author

This was the most useful problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment