Do not repeat javascript protocol number

Asked

Viewed 74 times

1

I would like you not to repeat the values, and click show the code already without repetition

var vetor = [];
var auxiliaProtocolo = document.querySelector(".type");
var limiteMaximo = CheckMaxProtocol();
var botao = document.querySelector(".botao");

botao.addEventListener("click", function() {

  var verificadorVetorCheio = verificaTotalVetor(vetor);
  if (verificadorVetorCheio == true) {
    return;
  }

  var resultado = geraProtocolo();
  vetor.push(resultado);

  for (var i = 0; i < vetor.length; i++) {
    for (var j = i + 1; j < vetor.length; j++) {
      if (vetor[i] == vetor[j]) {
        vetor.pop(vetor[j]);
        var result = geraProtocolo();
        if (vetor[i] != result) {
          vetor.push(result);
          break;
        }
      }
    }
  }
});

var botao2 = document.querySelector(".botao2");
botao2.addEventListener("click", function() {
  if (vetor.length > 0) {
    var novoProtoco = document.createElement("p");
    auxiliaProtocolo.appendChild(novoProtoco);
    novoProtoco.innerHTML = "Protocolo: " + vetor;
  }
});
  • 2

    You can join HTML and explain what should happen to reproduce the problem?

  • A non-repeating number is an auto_increment or rather complex randomness algorithm (which would be in your case with js).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.