Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiply Resursion JS
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