Skip to content

Instantly share code, notes, and snippets.

@MohdSaifulM
Created November 30, 2022 15:59
Show Gist options
  • Save MohdSaifulM/80d7cde059b5bf9e453101e368cbe0a2 to your computer and use it in GitHub Desktop.
Save MohdSaifulM/80d7cde059b5bf9e453101e368cbe0a2 to your computer and use it in GitHub Desktop.
Algorithms - Recursion
function productOfArray(arr) {
// Base case
if (arr.length === 1) return arr;
// Recursive case
return arr[0] * productOfArray(arr.slice(1));
}
// productOfArray([1,2,3]) // 6
// productOfArray([1,2,3,10]) // 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment