title: How to create a nested filter with lodash
body: <p>I have the following nested JSON data structure. Each node can have any number of children and the data can be any number of nodes deep.</p>
  
  <pre><code>[{
      id : "a",
      path : "a"
  }, {
      id : "b",
      path : "b"
  }, {
      id : "c",
      path : "c",
      children: [{
          id : "a",
          path : "c/a"
      }, {
          id : "b",
          path : "c/b",
          children: [{
              id : "a",
              path : "c/b/a"
          }, {
              id : "b",
              path : "c/b/b"
          }]
      }]
  }]
  </code></pre>
  
  <p>I need to create a function in lodash (v3.10.1) which returns a nested JSON object of matching paths, and any parent objects.
  For example, if I was to search on "b" the filter should return the following:</p>
  
  <pre><code>[{
      id : "b",
      path : "b"
  }, {
      id : "c",
      path : "c",
      children: [{
          id : "b",
          path : "c/b",
          children: [{
              id : "a",
              path : "c/b/a"
          }, {
              id : "b",
              path : "c/b/b"
          }]
      }]
  }]
  </code></pre>
  
  <p>My initial attempt was like this but it did work:</p>
  
  <pre><code>const filterTree = (filter, list) =&gt; {
      return _.filter(list, (item) =&gt; {
          if (item.path) {
              return _.includes(item.path.toLowerCase(), filter.toLowerCase());
          } else if (item.children) {
              return !_.isEmpty(filterTree(filter, item.children));
          }
      });
  };
  </code></pre>
  
  <p>Any help would be much appreciated </p>