How to find 'overlapping' values from an array of objects in JavaScript?
<p>Given two arrays of objects, how can I find all objects that contain an 'overlapping' value (e.g. price in this case)?</p>

<p>For example, given array A and array B, how can I find all objects where the "price" is either an exact match (e.g. 20, 30) or contained within this overlap (e.g. 20.45)? </p>

<pre><code>var A = [
  { "id" : 1, "price" : 50, "quantity": 2 },
  { "id" : 2, "price" : 40, "quantity": 2 },
  { "id" : 3, "price" : 30, "quantity": 2 }, // yes
  { "id" : 4, "price" : 20, "quantity": 2 }  // yes
];

var B = [
  { "id" : 5, "price" : 30, "quantity": 2 }, // yes
  { "id" : 6, "price" : 20.45, "quantity": 2 }, // yes
  { "id" : 7, "price" : 20, "quantity": 2 }, // yes
  { "id" : 8, "price" : 10, "quantity": 2 },
  { "id" : 9, "price" : 5, "quantity": 2 }
];


// Goal
var C = [
  { "id" : 3, "price" : 30, "quantity": 2 }, // yes
  { "id" : 4, "price" : 20, "quantity": 2 }  // yes
];
var D = [
  { "id" : 5, "price" : 30, "quantity": 2 }, // yes
  { "id" : 6, "price" : 20.45, "quantity": 2 }, // yes
  { "id" : 7, "price" : 20, "quantity": 2 }, // yes
];
</code></pre>

<p>My goal is to keep them separated into their own arrays (C &amp; D). But if the end result needs to be one combined array, that's okay. I can probably make that work too. Anything that works would make me happy right now.</p>

<p>I've tried Underscore's intersection. If A &amp; B were simple arrays containing integers rather than objects, then intersection would work to find the exact matches (e.g. 30 &amp; 30, 20 &amp; 20), but it still wouldn't include 20.45, which I need as well. And, of course, I have an array of objects instead of simple arrays, which makes it a bit harder as well.</p>
