Pairwise Challenge Solution

My Solution

Challenge: Pairwise

Code

function pairwise(arr, arg) {

 // Return if the array is empty

 if (arr.length === 0) return 0;

 

 var result = [];

 // Reducer function

 const reduce = (accumulator, currentValue) => accumulator + currentValue;

 // Looping through every element in the array

 for(var i=0; i<=arr.length; i++) {

   // Looping through every successive element in the array

   for(var j=i+1; j<=arr.length; j++) {

     

     // Checking if sum of the values at position i & j are equal to the 2nd argument

       if(

         arr[i] + arr[j] == arg &&

         (result.indexOf(i)<0 && result.indexOf(j)<0)

       ) {

          //Pushing the indexes in an array 

         result.push(i);

         result.push(j);

       }

     }

   }

   // Returning the sum of the indexes that matched the condition

 return result.reduce(reduce);

}

pairwise([], 100);

Explanation
The function uses two loops to make every possible combination.
First one loops through every element in the array
Second one loops through every element after the element in the first loop.
If the condition is met, the value of i & j i.e. the index values are pushed into an array.
Finally, the array is reduced to get the final answer.

Links
Array
Reduce Array

Link to the challenge:

Hello there.

Thank you, for your contribution. For future contributions, please wrap your solution within :

[details]
```
code goes here...
```
[/details]

Also, provide all of the necessary code to pass the challenge.

Also, when you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor ( </> ) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I’m not sure what was missed from my end. Everything you mention, was done before posting. Nor do I notice any difference in the edits made.
Anyway, thanks for the input.

I added the details part.