I've been trying to figure out how to count the number of nested arrays recursively in javascript but I can't seem to wrap my head around how you would do that. Like I know we'll need to use a count variable in there and we'll need to be able to access the elements but how can we count each time a new array is seen inside? Here's the problem: Given a nested array where each element may be 1) an integer or 2) an array, whose elements themselves may be integers or further arrays, count the total number of arrays.
I've tried this and I have no clue what I'm doing when it comes to deciding whether we've seen a new array.
`
function countArrays(array) {
//counting the first array
let sumTotal = 1;
for(let element in array);
if(Array.isArray(array))
sumTotal += countArrays(array)
};
console.log(countArrays([1, 2, 3])) // 1
console.log(countArrays([1, [1, 2, 3], 3])) // 2
`