title: To find object whereabouts in array of objects
body: <pre><code>function whatIsInAName(collection, source) {
    var result = [];
    var arr1 = Object.keys(source);
    console.log(arr1);
  
    for (var i = 0; i &lt; collection.length; i++) {
      for (var j = 0; j &lt; arr1.length; j++) {
        if (collection[i].hasOwnProperty(arr1[j]) === false) { //Check 1 if false go to next object  in collection
          break;
        } else if (collection[i].hasOwnProperty(arr1[j])) {
          console.log(source[arr1[j]], collection[i][arr1[j]])
          if (source[arr1[j]] !== collection[i][arr1[j]]) { //Check 2 if value is not equal break loop and goto next object in collection
            break;
          }
          continue; // if both check passes go for  next  property of source to check in object;
        }
        result.push(collection[i]); //if all values are present and checked in object push it in result array.
      }
    }
    return result;
  }
  
  console.log(whatIsInAName(
    [
      { a: 1, b: 2 },
      { a: 1 },
      { a: 1, b: 2, c: 2 }
    ], {
      a: 1,
      b: 2
    }
  ));
  </code></pre>
  
  <p>I couldn't figure out the problem in my logic. I try to debug it even but can't find what the hell is a problem with logic.The program is to make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument) Kindly help me over, please. </p>
  
  <pre><code>whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 }) 
  </code></pre>
  
  <p>should return </p>
  
  <pre><code>[{ "a": 1, "b": 2 }, { "a": 1, "b": 2, "c": 2 }].
  </code></pre>
  
  <p>and</p>
  
  <pre><code>whatIsInAName([{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }], { "a": 1 }) 
  </code></pre>
  
  <p>should return </p>
  
  <pre><code>[{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }].
  </code></pre>