title: With Underscore, how do I recursively flatten an array of objects?
body: <p>I have a tree/traversable object that looks like this:</p>
  
  <pre><code>                var data = {children: [
                  {
                  name: 'foo',
                  url: 'http://foo',
                  children: [
                      {
                      name: 'bar',
                      url: 'http://bar',
                      children: []
                  }
                  ]
              },
              {
                  name: 'baz',
                  url: 'http://baz',
                  children: []
              },
              {
                  name: 'biff',
                  children: []
              }
              ]};
  </code></pre>
  
  <p>What I need to do is be able to flatten the data into a single dimensional list:</p>
  
  <pre><code>var flattenedData = [{name: 'foo', url: 'http://foo'}, {name: 'bar', url: 'http://bar'}, {name: 'baz', url: 'http://baz'}, {name: 'biff'}];
  </code></pre>
  
  <p>Currently, I've created a recursive helper function to walk the data structure and push the results onto an array. I'd like to do this more functionally if possible. Something like:</p>
  
  <pre><code>var flattenedData = _.chain(data.children).flatten().filter(function(item){//real filtering; return item;}).value();
  </code></pre>
  
  <p>The problem is, flattening doesn't seem to flatten an array of objects, just simple arrays. I could be wrong. </p>
  
  <p>How would I perform this task in a more functional way without traversing the tree in a helper function?</p>