From mozillas js docs:
for (variable of iterable) {
statement
}
This is the standard for of statement in js and I want to do something like this:
for (variable of iterable && variable of iterable) {
statement
}
I just need the loops to not iterate and then iterate again for each nested for of loop. So something that is similar would be great for my needs but the above seems preferable.
I have 2 arrays that I am trying to iterate through and would like to create objects and check for their equality(or something else) further down.
Example scenario:
for (variable1 of iterable1 && variable2 of iterable2) {
//code
if (variable1 === variable2){
//do something
}
}
my code:
if (_.intersection(selections[i],questions[i].correctAnswer)) {
for (const selection of selections[i]) for (const answer of questions[i].correctAnswer) for(const item of questions[i].qPoints) {
if (selection === answer){
numCorrect += item;
console.log(numCorrect)
}
}
}
}
Basically what I am doing with intersection is checking if the two arrays intersect using underscoreJS. After that, I am trying to create objects for each of these arrays. Firstly, to check whether or not arrays are equal at any point, and if so incrementing numCorrect by the value of the correctanswer at that index(qPoints). The issue is with nested for loops, I am getting the value of qPoints by some multiple(due to excessive iterations).