title: How to assert partially deep equal/compare objects in javascript?
body: <p>I have an API and I want to assert that at least the expected data is returned. I don't care if more data is returned.</p>
  
  <p>Therefore I want to compare two objects (<code>expected</code> and <code>actual</code>) where all attributes of <code>expected</code> must be equal to <code>actual</code>, but <code>actual</code> may contain more attributes:</p>
  
  <pre><code>var expected = {
      foo: 1,
      bar: {
          x1: 42,
          a1: [
              1,
              2,
              {
                  x: 7
              }
          ]
      }
  }
  
  var actual = {
      foo: 1,
      whatever: 55, // to be ignored
      additional: { // to be ignored
          ignore: 1
      },
      bar: {
          x1: 42,
          a1: [
              1,
              2,
              {
                  x: 7,
                  y: 8   // to be ignored
              }
          ]
      }
  }
  
  partiallyEqual(expected, actual) // returns true
  </code></pre>
  
  <p>Some more examples:
  </p>
  
  <pre><code>partiallyEqual({x: 1}, {a:2, x:1}) // return true
  partiallyEqual({x: 1}, {a:2, x:2}) // return false (x is different)
  </code></pre>
  
  <p>Arrays may (optionally) be subject to partial equivalent, if <code>actual</code> contains additional elements.</p>
  
  <pre><code>partiallyEqual([1, 3], [1, 2, 3]) // return true
  partiallyEqual([3, 1], [1, 2, 3]) // return false (different order)
  </code></pre>