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

149
Visualizações
how can I skip two numbers and then get the next three numbers?

For a given range of numbers, how can I skip two numbers and then get the next three numbers?

e.g. For the range 0..20

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

for (let list = 0; list < 100; list++) {
  console.log(list);
}

I need to get this type of result:

2, 3, 4, 7, 8, 9, 12, 13, 14....

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Loop through from your start to the end. Use modulus arithmetic to determine which part of the 5 number cycle the number lies on. If it's the 0th, or 1st then ignore, otherwise add them to your result:

let start = 0;
let end = 20;

let result=[];
for(let i=0; i<(end-start); i++)
{
  let mod = i % 5;
  switch(mod)
  {
    case 0:
    case 1:
      // Ignore these numbers
    break
    case 2:
    case 3:
    case 4:
      result.push(start+i);
    break;
  }
}

console.log(result);

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