Pairwise (Wrong test case)

Pairwise (Wrong test case)
0

#1

Tell us what’s happening:

Your code so far

function pairwise(arr, arg) {

  return Object.entries(arr.reduce(function(pairs,curr,id,self){
   var other = self.indexOf(arg-curr,id+1);
   if(other != -1) {
     var pair = curr<arg-curr?curr:arg - curr;
     if(pairs.hasOwnProperty(pair)){
       pairs[pair] = Math.min(pairs[pair],id+other);
     } else {
       pairs[pair] = id+other;
     }
   }
   return pairs;
 },{})).reduce(function(sum,val){
   return sum + val[1];
 },0);
  
}

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

Your browser information:
Google Chrome
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:

The testcase 4 is wrong.

Given: pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.
Actually it should be pairwise([0, 0, 0, 0, 1, 1], 1) should return 4.


#2

See the following diagram for why the correct answer is 10.

Since there are multiple pairs, you sum the indices of the them per the instructions below:

If multiple pairs are possible that have the same numeric elements but different indices, return the smallest sum of indices. Once an element has been used, it cannot be reused to pair with another.