Https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/pairwise

Tell us what’s happening:
some test cases are not passing, here is my solution, please let me know what I’m doing wrong here?

Your code so far


function pairwise(arr, arg) {
let array = [];
for(let i=0; i<arr.length-1; i++){
  for(let j=i+1; j<arr.length; j++){
    if(arr[i]+arr[j] === arg)array.push(i,j)
  }
}
return array.reduce((a,b)=>a+b,0)
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Pairwise

Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/pairwise

Why not try to explain your algorithm to us? Do you understand why array is:

[ 0, 1, 0, 2, 1, 2 ]

when your function runs for the following test case?

pairwise([1, 1, 1], 2);

Yes Sir ,
these test case are not passing in case of repeating elements

If you can not explain your algorithm, then I suggest starting over and write out the algorithm first and then once you have validated the test cases would work correctly with it, then (and only then) transcribe your working algorithm to JavaScript.