Skip to content

Instantly share code, notes, and snippets.

@thexmanxyz
Created May 4, 2020 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thexmanxyz/13d1fb317ec02ec70cc89e68d926d40b to your computer and use it in GitHub Desktop.
Save thexmanxyz/13d1fb317ec02ec70cc89e68d926d40b to your computer and use it in GitHub Desktop.
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