How would one access each element in a mulidimensional array without using #flatten?
<p>I already flunked an assessment a little while ago but this question is still bugging me. The idea is to add all the elements of a multidimensional array like this: <code>[1,[2,3],4,[5,6,[7]]]]</code> and add them up as if they were all one-line, like <code>1+2+3+4+5+6+7</code>, without being able to use <code>#flatten</code>. I got about as far as removing all the integers (like 1 and 4) and adding them into its own variable and then trying to reduce(:+) the 2nd level arrays( <code>[2,3]</code>, etc), but I can't figure out how to write a loop that will delve deeper into the dimensions, like the <code>[7]</code>. How would one do that?</p>

<p>Code I've tried thus far</p>

<pre><code>def multi_array_sum(arrays)
    #need to add up all array elements
    num = 0
    arr = {}
    arrays.each {|int| num = num + int if int.class == Fixnum; arrays.delete(int)}
    array.map do |numz|
        num = num + numz.reduce(:+)
    end    
end
</code></pre>