const numbers = [1, 2, 3, 4, 5];function recursiveMaxSubarraySum(nums, startIndex = 0, currentSum = 0, maxSum = -Infinity) {
if (startIndex === nums.length) {
return maxSum;
}
currentSum = Math.max(nums[startIndex], currentSum + nums[startIndex]);
maxSum = Math.max(currentSum, maxSum);
return recursiveMaxSubarraySum(nums, startIndex + 1, currentSum, maxSum);
}
const result = recursiveMaxSubarraySum([-2, 1, -3, 4, -1, 2, 1, -5, 4]);
console.log(result);Ответ: 6
JavaScript test | #JavaScript