I’m taking a gamble by answering this.. but I’m assuming that you want to keep on adding two indexes within your array that are next to each other, to see if they’d equal any value in your second array?
Also, I have no idea why you’re using a nested loop. You only need to traverse one array, not two.
var myArray = [ 2, 3, 4 ];
var myOtherArray = [ 5, 6, 7 ];
var sum = 0;
for ( var i = 0; i < myArray.length-1; i++ ) {
sum = myArray[i] +myArray[i+1];
if (myOtherArray.indexOf[sum] != -1 ) {
console.log ("matching");
}
else {
console.log ("no matching");
}
}
the result should spit out “matching” twice.
Because 2+3 = 5, which exists in the second array. And 3+4 = 7, which also exists in the second array.
4
solved for every value in array B, want to find the consecutive values in A