title: Ordering recursive function results in arrays of arrays
body: <p>I am currently dealing with in issue in writing a recrusive function to order some json data. I have several nested arrays of objects which i need to order into single slides. The structure is similar to the following :</p>
  
  <pre><code>[
  {
      "title": "a",
      "children": [
          {
              "title": "a-a",
              "children": [
                  {
                      "title": "a-a-a"
                  },
                  {
                      "title": "a-a-b"
                  }
              ]
          },
          {
              "title": "a-b",
              "children": [
                  {
                      "title": "a-b-a"
                  },
                  {
                      "title": "a-b-b"
                  }
              ]
          }
      ]
  },
  {
      "title": "b",
      "children": [
          {
              "title": "b-a",
              "children": [
                  {
                      "title": "b-a-a"
                  },
                  {
                      "title": "b-a-b"
                  }
              ]
          },
          {
              "title": "b-b",
              "children": [
                  {
                      "title": "b-b-a"
                  },
                  {
                      "title": "b-b-b"
                  }
              ]
          }
      ]
  }
  ]
  </code></pre>
  
  <p>I have written a recursive function :</p>
  
  <pre><code>var catalog = {
  
  init: function() {
  
      var _this = this;
  
      $.getJSON("catalog.json", function(data) {
  
          _this.slides = [];
          _this.parseCategories(data.catalog.category,-1,0);
  
      });
  
  },
  
  parseCategories: function(array, depth, prevParent) {
      ++depth;
  
      if (!this.slides[depth]) this.slides[depth] = [];
      if (!this.slides[depth][prevParent]) this.slides[depth][prevParent] = [];
  
      this.slides[depth][prevParent].push(array);
  
      for (var i = 0; i &lt; array.length; i++) {
  
          if (array[i].category) {
  
              this.parseCategories(array[i].category, depth, i);
          }
      }
  
  }
  
  }
  
  catalog.init();
  </code></pre>
  
  <p>This outputs :</p>
  
  <p><a href="https://i.stack.imgur.com/hAlgy.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hAlgy.jpg" alt="enter image description here"></a></p>
  
  <p>However instead of retrieving the data for my third slide under format :</p>
  
  <p>a-a-a</p>
  
  <p>a-b-a</p>
  
  <p>a-c-a</p>
  
  <p>I would like to get</p>
  
  <p>a-a-[a,b,c]</p>
  
  <p>I was wondering if that was possible since I'm not very good at handling recursive processes. I hope I was clear and thank you for reading this.
  I basically need to keep my original data structure but remove the first depth level for each iteration (slide in a slider that represent increasing depths in my data structure).</p>