Ruby: how to know depth of multidemensional array
Posted
by
hqt
on Stack Overflow
See other posts from Stack Overflow
or by hqt
Published on 2012-06-02T12:08:13Z
Indexed on
2012/11/05
23:01 UTC
Read the original article
Hit count: 191
This is my problem I have met in my assignment.
- Array A has two elements: array B and array C.
- Array B has two elements: array D and array E
- At some point, array X just contains two elements: string a and string b.
I don't know how to determine how deep array A is. For example:
arrA = [
[
[1,2]
]
]
I have tested by: A[0][0][0] == nil
which returns false
. Moreover, A[0][0]..[0] == nil
always returns false
. So, I cannot do this way to know how deep array A is.
© Stack Overflow or respective owner