title: Complex table merging javascript & jquery algorithm
body: <p>I have a rather unique problem that I'm having trouble solving. I have a 2 x 3 table, arranged like shown below. </p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>_<em>1</em>__<em>_</em>_</strong><em>2</em>__ <br>
  1-|<strong><em>_</em>__<em>_</em></strong>|<em><strong></em>__<em>_</em>_</strong>|<br>
  2-|<strong><em>_</em>__<em>_</em></strong>|<em><strong></em>__<em>_</em>_</strong>|<br>
  3-|<strong><em>_</em>__<em>_</em></strong>|<em><strong></em>__<em>_</em>_</strong>|<br></p>
  
  <p>Data is populated into the cells of the table. Sometimes, the data in a column or row can be the same. For example, if (1,1) and (1,2) have the same data. In some cases (1,1), (1,2), and (1,3) can all have the same data. If the values in the cells are the same, and adjacent, they need to be merged. For example, if (1,1) and (1,2) both have a value of "100", the two cells get merged. I've done this manually by using jquery like: </p>
  
  <pre><code>(1,2).hide();
  (1,1).attr("rowspan", "2");
  </code></pre>
  
  <p>I hide the (1,2) cell instead of delete, since the tables can be reset to the original 2x3 and then repopulated if needed. Manually, this works great, but I need a dynamic method. Below is the overall goal of what needs to be accomplished.</p>
  
  <ul>
  <li>If two vertically adjacent cells or three vertically adjacent cells in their respective columns have a values that are equal, then those cells are merged together. </li>
  <li>Row cells, like (1,1) and (2,1) can have duplicated data, and are never merged. </li>
  <li>For reference, the groups of cells that are compatible to be merged are {(1,1),(1,2)}, {(1,1),(1,2),(1,3)}, {(1,2),(1,3)}, {(2,1),(2,2)}, {(2,1),(2,2),(2,3)}, {(2,2),(2,3)}</li>
  <li>Multiple merges can happen at a time. For example: {(1,1),(1,2)} have the same data, and {(2,1),(2,2),(2,3)} have the same data. Both groups are individually merged.</li>
  </ul>
  
  <p>My main question is, how would I go about writing an algorithm to do this, without writing out every possible situation. Can someone show me an example of something that would work? I realize this is complex, so feel free to ask questions for clarification. Thanks so much in advanced. This is a huge help!</p>