计算树的深度

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
  <script>
    var obj={
      a:{
        b:{
            c:{
                d:{
                    e:222
                    }    
                }
          }
    },
       a1:{
        b:{
            c:{
                d:{
                    e:{
                        f:{}
                        }
                    }    
                }
          }
    }
    
    }
    function deepObj(obj){
      var number={};
        for(var item in obj){
            if(obj[item]){
                number[item]=0;
                deepSearch(obj[item],item)
            }
        }
    console.log(number);
    return max(number);
      function deepSearch(obj,i){
        for(var item in obj){
            if(obj[item]!=undefined){
              number[i]++;
              deepSearch(obj[item],i);
                }
            }
          }
    }
    function max(obj){
      let max=0;
      for(var item in obj){
        if(max<obj[item]){
          max=obj[item];
        }else{
          
        }
      }
      return max;
    }
    console.log(deepObj(obj));
  </script>
<body>
 
</body>
</html>
学而不思则罔,思而不结则殆,结而不看,一事无成
原文地址:https://www.cnblogs.com/windseek/p/8193077.html