What this should be able to do is take in a 2D array filled with one letter values and return an array of all the shared values. This is what I have so far:
var res = array[0].filter(function(x){
return array.every(function(y){
return y.indexOf(x) >= 0
})
});
return res;
This is in some form of working state but only under certain condition which makes it very hit and miss. Working as intended:
var array = [["x","x"],
["x","x","x"]];
This returns the expected array of ["x","x"] but when like this:
var array = [["x","x","x"],
["x","x"]];
It returns ["x","x","x"]
As you can see the two arrays only share 2 common x's but the code doesn't reflect that in different situations. Also it should be able to handle arrays with other letters like so:
var array = [["x","x","z","y","y"],
["x,"x","x","y"],
["x","x","z","y"]];
With something like this it should return ["x","x","y"] as all arrays share 2 common x's and 1 common y
yin the 3rd array.