# Product Sum

<figure><img src="https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-04ff07b8d0f5947f51140c423d445df4e40c1570%2FScreenshot%202023-01-20%20at%2019.55.24.png?alt=media" alt=""><figcaption></figcaption></figure>

```jsx
// Tip: You can use the Array.isArray function to check whether an item
// is a list or an integer.
function productSum(arr) {
  return findProductSum(arr);
}

function findProductSum(arr, depth = 1) {

  let sum = 0;
  for (const value of arr) {
    if (!Array.isArray(value)) {
      sum += value;
      continue;
    }

    sum += findProductSum(value, depth + 1);
  }

  return sum * depth;

  
}

// Do not edit the line below.
exports.productSum = productSum;
```
