We are going to write a function called sumArray that will accept an array, ar, as an argument.

For this function, you are given a jagged array. A jagged array is an array that contains a combination of numbers and other arrays. The arrays can be multiple levels deep.

The goal of the function is to find the sum of all the numbers inside the jagged array.

Example:

let ar = [1, 2, [15, [23], [5, 12]], [100]];

//output: 158

Next, we will find a way to make our function traverse through all the inner arrays to get our sum. One key function to make this happen is recursion.

#javascript

JavaScript Algorithm: Calculate Sum of All Numbers in a Jagged Array
1.85 GEEK