Pairwise Finally worked but I cant even explain how it works. Is it okay?

And I did it by myself. I had an algorithm in mind to start with, but when it failed, I just… did trial and error most of the way forward - of course with some thought.

function pairwise(arr, arg) {
  var sum = 0;
  var used = [];
  for(var i = 0; i < arr.length-1; i++){
    for(var j = i+1; j < arr.length; j++){
      if(arr[i] + arr[j] == arg){
        if(used.includes(i) || used.includes(j, j)){
          continue;
        } else {
            sum += (i+j);
            used.push(i, j);
          i++;
          j++;
        }
      
      }
    }
  }
  return sum;
}

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