Nested Sum Recursion

Recursion Arrays Nested Sum

Problem: Nested Sum Recursion

In celebration of National Pie Day on January 23, let's slice through layers of nested arrays! Your task is to write a function that recursively computes the sum of all integers within a nested array structure. The array may contain integers as well as other arrays, and those inner arrays may also contain integers or further arrays, and so on.

Example

For example, given the nested array:

[1, [2, 3], 4, [5, [6]]]

Your function should return 21 because:

1 + 2 + 3 + 4 + 5 + 6 = 21

Requirements

  • Use recursion to solve the problem.
  • Assume the input will always be a valid nested array structure containing only integers or nested arrays.
  • The solution should be language-agnostic and understandable in any language.

Starter Code

Below are simple starter code templates for various programming languages. Complete the function implementations to pass the example and any additional test cases you create.