Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save qodirovshohijahon/02916e314cd18f49729c50d673c7d367 to your computer and use it in GitHub Desktop.
Save qodirovshohijahon/02916e314cd18f49729c50d673c7d367 to your computer and use it in GitHub Desktop.
Subtract the Product and Sum of Digits of an Integer
**
* @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