SubhanUllah Posted September 30, 2022 Report Posted September 30, 2022 /* * Return the depth of recursive array a. * Any array has a depth of at least one. * Non-arrays always have a depth of zero. */ function arrayDepth(a) { var depth = 0; if (Array.isArray(a)) { for (var i in a) { depth = Math.max(depth, arrayDepth(a[i])); } depth++; } return depth; }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now