Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!