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
https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/