Skip to content

Commit 8f619ee

Browse files
authored
Create 1281-subtract-the-product-and-sum-of-digits-of-an-integer.js
1 parent 19b9b62 commit 8f619ee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const subtractProductAndSum = function(n) {
6+
if(n === 0) return 0
7+
let sum = 0, product = 1
8+
n = '' + n
9+
for(let ch of n) {
10+
sum += +(ch)
11+
product *= +(ch)
12+
}
13+
return product - sum
14+
};

0 commit comments

Comments
 (0)