how do I imprint in Crecente order one at each click

Asked

Viewed 29 times

-2

["C-1", "C-2", "C-3"], ["R-1","R-2", "R-3"], ["P-1","P-2", "P-3"] como faço para imprir em Crecent order and with priority one at each example click :

password with P comes in 1

password with R comes in 2

password with C comes in 3

someone has an idea to do?

const listaDeSenhaComum = [];
const listaDeSenhaRapida = [];
const listaDeSenhaPrioritaria = [];

let senhaComum = 1;

function gerarSenhaComum() {
  let senhaComumGerada = `C-${senhaComum++}`;
  listaDeSenhaComum.push(senhaComumGerada);
  console.log(listaDeSenhaComum);
}

let senhaRapida = 1;

function gerarSenhaRapida() {
  let senhaRapidaGerada = `R-${senhaRapida++}`;
  listaDeSenhaRapida.push(senhaRapidaGerada);
  console.log(listaDeSenhaRapida);
}

let senhaPrioritaria = 1;

function gerarSenhaPrioritaria() {
  let senhaPrioritariaGerada = `P-${senhaPrioritaria++}`;
  listaDeSenhaPrioritaria.push(senhaPrioritariaGerada);
  console.log(listaDeSenhaPrioritaria);
}

ai in html every time someone clicks on call proxímo, print in priority order one every click.

  • R passwords should only be printed if there is no one in P, following the same for C and R?

  • that’s exactly what

  • Sorting lists is the least of the problems. Questions are: How do you define the type of password each user will receive? How many boxes? How do you link the password to the boxes? How do you define whether a box is free or not? Where is the HTML code that will interact with the user?

1 answer

0


Just use the function shift, following the order of priorities, thus:

listaDeSenhaPrioritaria.shift() || listaDeSenhaRapida.shift() || listaDeSenhaComum.shift()

In case one of the arrays is empty it passes to the next.

complete example:

const listaDeSenhaComum = [ 'C-1', 'C-2', 'C-3' ];
const listaDeSenhaRapida = [ 'R-1', 'R-2', 'R-3' ];
const listaDeSenhaPrioritaria = ['P-1'];

function proximo(){
  return listaDeSenhaPrioritaria.shift() || listaDeSenhaRapida.shift() || listaDeSenhaComum.shift() || 'Vazio'
}

console.log(proximo());
console.log(proximo());
console.log(proximo());
console.log(proximo());
console.log(proximo());
console.log(proximo());
console.log(proximo());
console.log(proximo());

// P-1
// R-1
// R-2
// R-3
// C-1
// C-2
// C-3
// Vazio

just call the function proximo in the page click event

  • thank you very much was already no idea kkk

Browser other questions tagged

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