Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
Bingo game problem: all elements of array in another array

I have a small problem. I have an array of 5 winning numbers and a random array draw of 10 numbers between 1 and 26. If all the elements of the winning array are found in the draw array, it should return WIN and LOSE if they aren't. It doesn't work. :(

function bingo(a) {
  let draw = [];
  let win = [2, 9, 14, 15, 7];
  for (let i = 10; i > 0; i--) {
    draw.push(Math.floor(Math.random() * 26 + 1));
  }
  if (win.every((r) => draw.includes(r))) {
    return "WIN";
  } else {
    return "LOSE";
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As I understand from your question, you are just confused because of low probability of matching. You can test it with a constant array to see. However, I see that you are using argument a that does not have any functionality in your function since you define and use just arrays draw and win inside the function

function bingo() {
  let draw = [];
  let win = [2, 9, 14, 15, 7];
  for (let i = 10; i > 0; i--) {
    draw.push(Math.floor(Math.random() * 26 + 1));
  }
  //Here you can change draw with [2, 9, 14, 15, 7] to test
  if (win.every((r) => draw.includes(r))) {
    console.log(draw);
    return "WIN";
  } else {
    console.log(draw);
    return "LOSE";
  }
}

bingo();

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda