Help Requested with Pairwise

Help Requested with Pairwise
0.0 0

#1

Hello. Could somebody help me pinpoint where I went wrong with the following code? I feel it should work. Thanks!

function pairwise(arr, arg) {
  var totalSum = 0;
  var sum = 0;
  var repeatedNum = [];
  for (var i = 0; i <arr.length-1; i++) {
    for (var j = i+1; j < arr.length; j++) {
      if (arr[i] + arr[j] === arg && repeatedNum.indexOf[i] == -1 && repeatedNum.indexOf[j] == -1) {
        sum = i + j;
        totalSum += sum;
        repeatedNum.push(i);
        repeatedNum.push(j);
      }
    }
  }
  return totalSum;
}

pairwise([1,4,2,3,0,5], 7);


#2

Took me a while to see this. I can see why you missed it too.

[ ] vs ( )

repeatedNum.indexOf[i] 
repeatedNum.indexOf(i) 

Invoke a function with ( ), access an array element with [ ]

I think it should work fine once you fix that.
Good luck!


#3

Thanks so much. I figured out that the problem was in the if-statement but still couldn’t find the mistake.