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 });
});
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});
});