Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 18, 2023
1 parent 3f8683a commit 1fe2696
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions coding_interviews/algoexpert/product-sum/product-sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function productSum(array, product = 1) {
let sum = 0;

for (let num of array) {
if (Array.isArray(num)) {
sum += productSum(num, product + 1) * product;
} else {
sum += num * product;
}
}

return sum;
}

0 comments on commit 1fe2696

Please sign in to comment.