Created
January 31, 2014 22:51
-
-
Save alienfluid/8744869 to your computer and use it in GitHub Desktop.
Find the maximum depth of a nested list structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = list(list("a", "b"), list(list(list(list(list("c")))), list(list("d"))), 1) | |
is_list = function (x) { | |
if (class(x) == "list") { | |
1 + max(sapply(x, is_list)) | |
} else { | |
0 | |
} | |
} | |
max(sapply(a, is_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment