I am trying to use javascript to remove duplicate entries in an array of arrays in which the duplicates will always be in an array of length 1. An example would be
[ [23, 46, 43, 44]
[46]
[52, 51]
[53]
[44]
[55, 66] ]
In this case I would want to remove the arrays [46] and [44], but leave [53]. The number of these single entry duplicate arrays is variable. Ideas?
Edit: Here's what I ended up doing that worked where stacks_array is the array of arrays.
function stacks_sanatizer(stacks_array){
var output_array = [],
used_cards =[];
used_cards[70] = undefined;
for (each_stak in stacks_array){
if((stacks_array[each_stak].length > 1) && (stacks_array[each_stak] !== "")){
for (i=0; i<stacks_array[each_stak].length;i++){
var card_number = stacks_array[each_stak][i].attrs.fill.substr(27).replace('.jpg)','');
used_cards[card_number - 1] = true;
}
}
}
for (each_stak in stacks_array){
if(stacks_array[each_stak] !== ""){
if(stacks_array[each_stak].length === 1){
card_number = stacks_array[each_stak][0].attrs.fill.substr(27).replace('.jpg)','');
if(used_cards[card_number - 1] !== true){
output_array.push(stacks_array[each_stak]);
used_cards[card_number - 1] = true;
}
}
else{
output_array.push(stacks_array[each_stak]);
}
}
}
//delete doubles
for(each_pile in output_array){
output_array[each_pile] = output_array[each_pile].filter(function(elem, pos) {
return output_array[each_pile].indexOf(elem) == pos;
})
}
return output_array;
}