title: creating a javascript recursive filter function
body: <p>Is there any way of making this function recursive so that I do not need to create a switch for each length of filter criteria ?</p>
  
  <pre><code>var data = [
    {a:'aaa',b:'bbb',c:'ccc',d:'ddd',e:'eee'},
    {a:'aaa',b:'bbb',c:'ccc',d:'eee',e:'fff'},
    {a:'xxx',b:'bbb',c:'ccc',d:'ddd',e:'fff'}
  ]
  
  
  function select(data,where){
    return data.filter(function(e){ 
      var k = Object.keys(where); 
      switch(k.length){     
        case 1: return (e[k[0]] == where[k[0]]);
        case 2: return (e[k[0]] == where[k[0]] &amp;&amp; e[k[1]] == where[k[1]]);
        case 3: return (e[k[0]] == where[k[0]] &amp;&amp; e[k[1]] == where[k[1]] &amp;&amp; e[k[2]] == where[k[2]]);
        case 4: return (e[k[0]] == where[k[0]] &amp;&amp; e[k[1]] == where[k[1]] &amp;&amp; e[k[2]] == where[k[2]] &amp;&amp; e[k[3]] == where[k[3]]);
        case 5: return (e[k[0]] == where[k[0]] &amp;&amp; e[k[1]] == where[k[1]] &amp;&amp; e[k[2]] == where[k[2]] &amp;&amp; e[k[3]] == where[k[3]] &amp;&amp; e[k[4]] == where[k[4]]);
      }
    })  
  }
  
  var where = {a:'aaa',b:'bbb'}
  
  console.log(select(data,where));
  </code></pre>