Looking to compare and combine multiple arrays that may have identical elements:
X = [1,2,3];
Y = [1,2,3];
Z = [1,2,3];
M = [10,11,12];
N = [10,11,12];
O = [10,11,12];
P = [13,14];
Q = [13,14];
If there are identical arrays, the goal is to form new arrays based on the similar ones:
R = [1,2,3];
S = [10,11,12];
T = [13,14];
Is it necessary to compare each element of one array to every element of the other arrays?
for (var x in X) {
for (var y in Y) {
if (X[x] == Y[y]) {
// create new arrays
}
}
}
Is there a more efficient method to achieve this, rather than iterating through all elements?
Any suggestions on the best approach?
Thank you!