Created
January 28, 2020 10:16
-
-
Save qodirovshohijahon/02916e314cd18f49729c50d673c7d367 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
** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var subtractProductAndSum = function(n) { | |
let num = n.toString().split(""); | |
let count = num.reduce((acc, sum)=>{ | |
acc += Number(sum); | |
return acc; | |
}, 0); | |
let mul = num.reduce((acc, sum)=>{ | |
acc *= Number(sum); | |
return acc; | |
}, 1); | |
return mul - count; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given an integer number n, return the difference between the product of its digits and the sum of its digits.
Example 1:
Input: n = 234
Output: 15
Explanation:
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15