Jump to content

Recommended Posts

Posted
/* 
 * 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; 
} 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...