title: How to compute the distance between a leaf and the root node in a tree structure
body: <p>I'm trying to create a tree structure. But I don't know how to use recursive methods.</p>
  
  <p>I'm loading an array that contains info and children.</p>
  
  <p>What I would like to know is, how far down is a node from the root?</p>
  
  <p>For exmaple: </p>
  
  <ul>
  <li>element with id 1 is 0 steps from the root</li>
  <li>element with id 12 is 1 steps from the root</li>
  <li>element with id 122 is 2 steps from the root</li>
  <li>element with id 13 is 1 steps from the root</li>
  </ul>
  
  <pre class="lang-js prettyprint-override"><code>const data = [
      {id: 1, title: 'foo', children: [
          {id: 11, parentId: 1, title: 'bar',},
          {id: 12, parentId: 1, title: 'baz', children: [
              {id: 121, parentId: 12, title: 'qux'},
              {id: 122, parentId: 12, title: 'quz'}
          ]},
          {id: 13, parentId: 1, title: 'corge'}
      ]}
  ];
  </code></pre>