i don’t know what to do?Please help me
Your code so far
function pairwise(arr, arg) {
return arg;
}
pairwise([1,4,2,3,0,5], 7);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/pairwise
What in particular about the instructions and example don’t you understand?
You might find it helpful to use pen and paper when looking at the example  this question took me a while to understand too
And then what i do?
i don’t understand what to do with numbers and pairwise
Let’s talk through the example then:
pairwise([7, 9, 11, 13, 15], 20)
When we call this function, we have the array arr
with elements [7, 9, 11, 13, 15]
in it. We want to find pairs of elements that add up to 20
. The number 20
is stored in the variable arg
.
We need to find pairs of numbers in that array that add up to 20
, so let’s start by looking at the first value, 7
. We’d need 13
to be in the list to have a pair, which we do! So [7, 13]
is a pair that adds to what we want!
7
was found at the start of arr
so its index is 0
. 13
is found in arr[3]
so its index is 3
. The question wants the sum of indices for the pair, so that’s 0 + 3
which is 3
.
Repeating the above for the other numbers shows us that there is another pair of elements in arr
that add up to arg
. 9 + 11
is also 20
, and we find them at indices 1
and 2
. Their index sum is 3
also.
Because we had multiple pairs, we add up their index sums, so 3 + 3
is 6
, which is the final answer we’re looking for, so we return
it.
Ok I try it and if don’t do it i question you
i tried last night but I don’t managed.Can you help me more??
Which part did you get up to?
I’ll give a few hints now as to one way you can break up the problem into smaller ones. (this isn’t the most efficient way to solve the problem, but it’s good enough and conceptually the most simple)

Write a function that finds the first index of a given number. We only want the first index of a given number if it appears multiple times, because of something the question asks. Hint: you can use .indexOf()
for this

Write a function that finds the difference between the value we want, and a given value. e.g. if we want a sum of 20, and we put in the number 3 and the function returns 17.

Write a function that looks at the array arr
, and for each value in arr
uses function 2 to find the difference, and then function 1 to find the index of the difference.
If in function 3 the difference can’t be found, move on to the next element. If in function 3 the difference is found, then store the sum of the indices somewhere.
Let me know if there’s something you don’t understand written here
Reply back and post your code, so we can see what you have tried so far.
To enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
thank you but i did it sorry for destraction