JSFiddle - React, Tailwind, and code Playground

by Paco86

JavaScript

// productOfArray([1,2,3]) // 6
// productOfArray([1,2,3,10]) // 60

function productOfArray(arr, i = 0) {
	if (arr.length == 0) return 0;
	if (i === arr.length) return 1;
  
  return arr[i] * productOfArray(arr, i + 1)
}

console.log(productOfArray([1,2,3,10]));