Skip to content

Commit 46c58ae

Browse files
author
Jaskaran Singh
authored
Create subtract_product_and_sum_integer.js
1 parent 199abe6 commit 46c58ae

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

subtract_product_and_sum_integer.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var subtractProductAndSum = function(n) {
6+
let numArr = [], prod = 1, sum = 0;
7+
8+
let createNumArray = (x) => {
9+
numArr.push(parseInt(x));
10+
}
11+
12+
n.toString().split("").map(createNumArray);
13+
14+
for(let i = 0; i < numArr.length; i++) {
15+
prod *= numArr[i];
16+
sum += numArr[i];
17+
}
18+
19+
return (prod-sum);
20+
};

0 commit comments

Comments
 (0)