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

89
Visualizações
Create 2 random series of 1-10 and write them in lines of 4 numbers Javascript

I want to create 2 random series of 1-10, en divide them into lines of 4. The first 10 have to be in the first lines, and the second 10 next. Important is the lines cannot have double numbers.

Example: 
    [4,7,3,1]
    [10,6,5,2]
    [9,8,1,5] // In this line you go from 1st to 2nd serie, an may not contain double numbers
    [3,2,9,7]
    [4,8,10,6]



For example if i put the numbers in ascending order, to make it more clear:
    [1,2,3,4]
    [5,6,7,8]
    [9,10,1,2] // In this line you go from 1st to 2nd serie, an may not contain double numbers
    [3,4,5,6]
    [7,8,9,10]

What i have so far:

let arr = [];
let arr2 = [];

for (i = 0; i <=1; i++) {
  while (arr.length < 10) {
    let r = Math.floor(Math.random() * 10) + 1;
    if (arr.indexOf(r) === -1) arr.push(r);
  }
arr2.push(arr)
arr = [];
}

console.log(arr2);

But this creates only 2 random array's of 10. I'm stuck from this point, hope someone can help me.

(input values all can be different, series, numberrange and 4 numbers per line)

about 4 years ago · Juan Pablo Isaza
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