Pairwise Help Please?! :/ Any help would be much appreciated

Pairwise Help Please?! :/ Any help would be much appreciated
0

#1

The following is my code. I know I am supposed to return a total, but I just want to see which values are going to be added together. Any idea why the last value it inputs into the array are wrong? My code only works for the first case. :confused:

function pairwise(arr, arg) {

var indexesToAdd = [];
var total = 0;
//The first loop below should go through each number in the array.
for (var i = 0; i < arr.length; i++) {
//now the inner loop will check if the adding to each number in array will equal arg. If it does, and the indexes do not match numbers that are already in the array, push both indexes to indexestoadd array.
for (var j = 1; j < arr.length /*&& (arr[i] + arr[j] !== arg) */; j++) {
if (arr[i] + arr[j] === arg) {
if (indexesToAdd.indexOf(i) === -1) {
indexesToAdd.push(i);
}
if (indexesToAdd.indexOf(j) === -1) {
indexesToAdd.push(j);
}
}
}

}

for (var y = 0; y < indexesToAdd.length; y++) {
total += indexesToAdd[y];
}

return indexesToAdd;
}

pairwise([0, 0, 0, 0, 1, 1], 1); //It won’t work for this test case.

pairwise([1, 4, 2, 3, 0, 5], 7) //But it will work for this case.