0
I will try to be brief in the description. I have, for example, two arrays. One of them has 6 indexes and the other 7.
I need to take the first 5 indexes of each array and perform a function, then take the remaining indexes of that array and perform another function. If the remaining indices are greater than 5, I have to take the 5 and then the others and so on.
The checks, I have no problem, but I’m having a hard time finding a way to fit the functions in each of the indexes
Edit: I tried something like this:
for (let i = 0; i < array.length; i++){
if (i === 5) {
// executa função para mod de 5
} else if (i > 5) {
if (i % 5 === 0) {
// executa função para maiores do 5, que formam outro conjunto de 5
} else {
// executa função para maiores do 5, mas que não formam um novo conjunto de 5
}
}
The problem is that besides these numerous ifs, I have not found a way, in each function within ifs, to use only the remaining indices for the function. I need to get to a certain index, pause, do the function, and go up to the next indices,.
To illustrate better, in the image I have two arrays, one on the left side with 6 indexes, containing the blocks and the other on the right side, with 7 indexes, containing the blocks. The function has to first call the sets of 5 blocks to go to the ground, then the sets that do not have 5 indices remaining in the array.
Put in the code you have so far, so we can help you better.
– Giuliana Bezerra
I put an example of what I tried
– Felipe Evangelista
What kind of functions are those that have within the
ifs
? If the execution is each5
just useif (i !== 0 && i % 5 == 0)
. Or you can even do thefor
to the multiplicity of5
below the size and do the remaining processing outside thefor
.– Isac
These functions are animated, using Tween. To try to explain, it’s a math game, each array is a set of blocks. Then there are two sets of block that are summed up. The answer is chosen by leaving a blank space on the floor for the blocks. The blocks then fit on the floor. First the sets of 5, then the others. It is hard to understand speaking like this, but I hope you have given a lightening rs
– Felipe Evangelista
The problem is that if you only do it to the multiple of 5, the rest are out of function
– Felipe Evangelista
How do I make sure the question doesn’t go as pending?
– Felipe Evangelista
Let me get this straight. You want to perform a function on indices 5, 10, 15 [...] of an array, and on the other indices perform another function?
– Máttheus Spoo
Not exactly indices 5, 10, 15... but indices up to 5, then indices up to 10, and while the remaining indices are not multiples of 5, type, only remain 3 indices, do another function
– Felipe Evangelista
I edited the post with an image to try to lighten a little rs
– Felipe Evangelista
Let me get this straight, first you have to perform the function with ALL sets of 5 that exist, only then do the function with sets smaller than 5?
– Nathan Schroeder
That, the order is first the sets of 5 fitting into the ground, then the smallest
– Felipe Evangelista