title: Why do we need to reduce the mapped Boolean values to a single value in a function?
body: <p>Why do we need to <code>reduce</code> the mapped Boolean Value to a single value at the end of the function?</p>
  
  <p>The purpose of the function is to filter an array of objects (first argument) with the <code>key</code> <code>value</code> pairs from another object (second argument).</p>
  
  <p>It should return another array of <code>object</code> with the objects from the first argument which matched both the <code>key</code> and <code>value</code> from the second argument.</p>
  
  <p>For example if the first argument is <code>[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]</code> </p>
  
  <p>And the second is <code>{ last: "Capulet" }</code></p>
  
  <p>The function should return <code>[{ first: "Tybalt", last: "Capulet" }]</code></p>
  
  <p>This is the solution I stumbled upon and can't understand how the <code>map(</code>) and <code>reduce()</code> work here.</p>
  
  <pre><code>function whatIsInAName(collection, source) {
    var srcKeys = Object.keys(source);
  
    return collection.filter(function (obj) {
      return srcKeys
        .map(function(key) {
          return obj.hasOwnProperty(key) &amp;&amp; obj[key] === source[key];
        })
        .reduce(function(a, b) {
          return a &amp;&amp; b;
        });
    });
  }
  </code></pre>
  
  <p>Thanks!</p>