---
title: "Comment by fengxh on \"fCC - Basic JavaScript: Replace Loops using Recursion\" | Hashnode"
description: "You can use reduce to finish the multiply action. function multiply ( arr ) { if (arr.length &lt;= 0 ) return 1 ; return arr.reduce( ( result, number ) =&gt; {"
url: "https://hashnode.com/posts/fcc-basic-javascript-replace-loops-using-recursion/5eb1d755352b69972eb69825/comment/5eb23406f89d4c762e707c62"
---

[Discussion](https://hashnode.com/posts/fcc-basic-javascript-replace-loops-using-recursion/5eb1d755352b69972eb69825)

Comment [fCC - Basic JavaScript: Replace Loops using Recursion](https://hashnode.com/posts/fcc-basic-javascript-replace-loops-using-recursion/5eb1d755352b69972eb69825)

[fengxh](https://hashnode.com/@fengxh)

[May 6, 2020](https://hashnode.com/posts/fcc-basic-javascript-replace-loops-using-recursion/5eb1d755352b69972eb69825/comment/5eb23406f89d4c762e707c62)

You can use `reduce` to finish the multiply action.

```
function multiply(arr) {
  if (arr.length <= 0) return 1;
  return arr.reduce((result, number) => {
    return result * number;
  }, 1); 
}
```

Another thing about recursion is tail optimization, it can reduce the usage of call stack to minimize space complexity.
