1
I can have a composition of N elements in an array that can be arranged as follows for example:
array with A, B, C and D... 12 possibilities.
arr1 = ["A|B","A|C","A|D","B|A","B|C","B|D","C|A","C|B","C|D","D|A","D|B","D|C"];
array with A, B and C... 9 possibilities.
arr2 = ["A","B","C","A|B","A|C","B|A","B|C","C|A","C|B"];
I need to create a draw so that I don’t repeat one of the elements, Exp:
arrDeSaida = ["B|A","D|C"]; //Válido
arrDeSaida = ["B|A","A|C"]; //inválido
arrDeSaida = ["B|C","A"]; //Válido
arrDeSaida = ["B|A","B"]; //inválido
The logic just isn’t adding up...
qtdElementos = ["A","B","C","D"];
for (var i = 0; i < qtdElementos.length; i++) {
for (var x = 0; x < qtdElementos.length; x++) {
if(x != i){
arr1.push(qtdElementos[i]+'|'+qtdElementos[x]);
}
}
}
for (var i = 0; i <= qtdElementos.length/2; i++) {
if(arr1.length >= 2){
posicao = arr1[i].split("|");
for (var j = ; j < arr1.length; j++) {
}
}
}
I stalled inside the second go, I don’t know what I could do..
If in the
arr1
already has for exampleA|C
the "A" and "C" can no longer be drawn?– Fernando Leal
yes, that’s the idea
– MarceloBoni