Grouping common values from multiple arrays
<p>I have multiple arrays in javascript with same number of elements.  I want to find common values and group them together into separate arrays like the following (using javascript and jquery) ...</p>

<pre><code>[1,2,3,4]
[1,2,3,5]
[1,2,3,6]
[1,2,4,3]
</code></pre>

<p>I want the following result:</p>

<p>1 / 2 / 3 / 4,5,6<br>
1 / 2 / 4 / 3</p>

<p>This should result in two separate sets of combinations as above. Below would not be correct:</p>

<p>1 / 2 / 3,4 / 3,4,5,6</p>

<p>because no arrays of [1,2,4,5] and [1,2,4,6] exist.</p>

<p>Here's my code</p>

<pre><code>&lt;input type="checkbox" class="cb4" value="1,2,3,4" /&gt;
&lt;input type="checkbox" class="cb4" value="1,2,3,5" /&gt;
&lt;input type="checkbox" class="cb4" value="1,2,3,6" /&gt;
&lt;input type="checkbox" class="cb4" value="1,2,4,3" /&gt;

for (i = 0; i &lt; 4; i++) {
    combos[i] = [];
}
$('input.cb4:checked').each(function(){
    var nums = this.value.split(',');
    for (i = 0; i &lt; nums.length; i++) {
        if ($.inArray(nums[i], combos[i]) == -1) {
            combos[i].push( nums[i] );
        }
    }
});

var bets = '';
for (i = 0; i &lt; combos.length; i++) {
    combos[i].sort(function(a,b) {return a-b});
    bets += combos[i] + ' / ';
}
</code></pre>

<p>The string bets has the value of: "1 / 2 / 3,4 / 3,4,5,6".  Again, this is not correct since there are no values of 1,2,4,5 or 1,2,4,6.</p>
