title: How to split an array of arrays based on certain condition?
body: <p>I have an array which contains groups of some adjacent rectangles:</p>
  
  <pre><code>var paths = [
    [3,4,6,7],
    [8,10],
    [13]
  ];
  </code></pre>
  
  <p>The rectangles are defined as follows:</p>
  
  <pre><code>var rectangles = [
    {id:1,left:[],right:[2]},
    {id:2,left:[1],right:[11]},
    {id:3,left:[2],right:[4]},
    {id:4,left:[3],right:[5]},
    {id:5,left:[11],right:[6,12]},
    {id:6,left:[5],right:[7]},
    {id:7,left:[6],right:[]},
    {id:8,left:[],right:[9]},
    {id:9,left:[8],right:[10]},
    {id:10,left:[9],right:[2]},
    {id:11,left:[2],right:[5]},
    {id:12,left:[5],right:[]},
    {id:13,left:[],right:[9]}
  ];
  </code></pre>
  
  <p>From the rectangles definition, i see that rectangles 4 and 6 are not neighbors, because 4 is not right of 6 and 6 is not left of 4. The same for 8 and 10.</p>
  
  <p>Now, i would like to split the paths array to have separate entries for every group of adjacent rectangles, like this:</p>
  
  <pre><code>result = [
    [3,4],
    [6,7],
    [8],
    [10],
    [13]
  ];
  </code></pre>
  
  <p>How can i split the array and create new entries when i find two consecutive id's of two non-adjacent rectangles?</p>
  
  <p>Fiddle with test data: <a href="https://jsfiddle.net/4jpy84k4/" rel="nofollow">https://jsfiddle.net/4jpy84k4/</a></p>
  
  <p><strong>EDIT:</strong>
  Final solution thanks to Tobias K.: <a href="https://jsfiddle.net/j1of5p4c/4/" rel="nofollow">https://jsfiddle.net/j1of5p4c/4/</a></p>