I'm sorry in advance that this code is super messy and inefficient, I am just learning, however I am concerned with one particular problem which I have outlined at the bottom.
The aim of this function is to return every unique array with no repetition of elements, from when every element of ArrTwo is put on the end of each element from arrOne.
function multOrdProduct(arrOne,arrTwo){
let backSet = [];
let finalSet = [];
let count = 0;
let tempArr = new Array(arrOne.length);
let permArrOne = [];
let permArrTwo = [];
let pushed;
let setPart = [];
let tempBackSort = [];
for(i=0; i < arrOne.length; i++){
permArrOne.push(arrOne[i]);
}
for(i = 0; i < arrOne.length;i++){
for(j = 0; j < arrTwo.length; j++){
setPart = permArrOne[i].map( x => x);
setPart.push(arrTwo[j]);
backSet.push(setPart);
}
}
// This makes backSet into the array which has every combination of the two arrays when all elements from arrTwo are put onto each element of arrOne
console.log(backSet);
count = 0;
for(z= 0; z < backSet.length - 1; z++){
backSet[count].sort();
tempBackSort = [];
for(k = 0;k < backSet[count].length - 1; k++){
if(tempBackSort.includes(backSet[count][k])){
backSet = backSet.filter(arr => (new Set(arr)).size == arr.length);
kon = 0;
break;
} else{
tempBackSort.push(backSet[count][k]);
kon = 1
}
}
if(kon===1){
count++;
}
backSet[count].sort();
}
// ^^ This filters out every array within backSet which has multiple of the same element
console.log(backSet);
let twoTempArr = backSet;
console.log(backSet[0] === backSet[2]);
return twoTempArr;
}
unArray = [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
duArray = [1,2,3,4]
console.log(multOrdProduct(unArray,duArray));
function multOrdProduct(arrOne,arrTwo){
let backSet = [];
let finalSet = [];
let count = 0;
let tempArr = new Array(arrOne.length);
let permArrOne = [];
let permArrTwo = [];
let pushed;
let setPart = [];
let tempBackSort = [];
for(i=0; i < arrOne.length; i++){
permArrOne.push(arrOne[i]);
}
for(i = 0; i < arrOne.length;i++){
for(j = 0; j < arrTwo.length; j++){
setPart = permArrOne[i].map( x => x);
setPart.push(arrTwo[j]);
backSet.push(setPart);
}
}
// This makes backSet into the array which has every combination of the two arrays when all elements from arrTwo are put onto each element of arrOne
console.log(backSet);
count = 0;
for(z= 0; z < backSet.length - 1; z++){
backSet[count].sort();
tempBackSort = [];
for(k = 0;k < backSet[count].length - 1; k++){
if(tempBackSort.includes(backSet[count][k])){
backSet = backSet.filter(arr => (new Set(arr)).size == arr.length);
kon = 0;
break;
} else{
tempBackSort.push(backSet[count][k]);
kon = 1
}
}
if(kon===1){
count++;
}
backSet[count].sort();
}
// ^^ This filters out every array within backSet which has multiple of the same element
console.log(backSet);
let twoTempArr = backSet;
console.log(backSet[0] === backSet[2]);
return twoTempArr;
}
unArray = [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
duArray = [1,2,3,4]
console.log(multOrdProduct(unArray,duArray));
The problem which I am having is that console.log(backSet[0] === backSet[2]); does not show true, even though when backSet is printed you can see that the first and third elements are the same. Are arrays within an array not equal if they have been sorted?