Created
May 4, 2020 09:48
-
-
Save thexmanxyz/13d1fb317ec02ec70cc89e68d926d40b to your computer and use it in GitHub Desktop.
Multiply Resursion JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function multiply(arr, n) { | |
if (n <= 0) { // return 0 if count is 0 or negative | |
return 0; | |
} else { // sum up the next n - 1 elements with the current element | |
return multiply(arr, n - 1) + arr[n - 1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment