Created
January 28, 2020 10:18
-
-
Save qodirovshohijahon/3cedc681351086d7141a0cb84d9fc6bd to your computer and use it in GitHub Desktop.
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
** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var subtractProductAndSum = function(n) { | |
let strNum = n.toString(); | |
let arr = strNum.split(""); | |
let mul = 1, count = 0; | |
for (let i = 0; i < arr.length; i++) { | |
mul *= arr[i]; | |
} | |
for (let j = 0; j < arr.length; j++) { | |
count += parseInt(arr[j]); | |
} | |
return mul - count; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subtract the Product and Sum of Digits of an Integer