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

219
Views
Occupy a number from incrementation

what's the best method for occupying certain numbers from incrementation? For example I have a code that increments a value. I want to occupy all multipliers of 7 so the array is (1,2,3,4,5,6,8,9,10,11,12,13,15..) so I can later on add my own values in the multipliers of 7.

let x = 0;

let Array1 = [
  { user: 'mark', id: 1412, requeue: false },
  { user: 'john', id: 2612, requeue: false },
  { user: 'leo', id: 3743, requeue: false },
  { user: 'adam', id: 2414, requeue: false },
  { user: 'hasan', id: 51, requeue: false },
];

let Array3 = [];

// Add to all except multiples of 7
Array1.forEach((user) => {
  if (x % 7 === 0) {
    // Skip the number 7, 14, 21...
  } else {
    x++;
    // Else push the user to Array3
    // Array3.push({ ...singer, position: x });
  }
});

// Adding elements only on multiples of 7
let i = 0;
Array2.forEach((singer) => {
  i++;
  Array3.push({ ...singer, position: i * 7 });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When x is a multiple of 7, just do an extra increment.

Array1.forEach((user) => {
  x++;
  if (x % 7 === 0) {
    x++;
  }
  Array3.push({...singer, position: x});
});

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!