Tell us what’s happening:
This is my code. I am not going through two tests.Probably I stuck at the sentence " Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element." Need help to get through this.
Your code so far
function pairwise(arr, arg) {
let nArr = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
if (arr[i] + arr[j] == arg) {
if (i != j) {
nArr.push([arr[i], arr[j]]);
}
}
}
}
console.log(nArr);
let result, fResult = 0;
for (let k = 0; k < nArr.length; k++) {
result = arr.indexOf(nArr[k][0]) + arr.indexOf(nArr[k][1]);
fResult += result;
}
console.log(fResult);
return fResult/2;
}
pairwise([0, 0, 0, 0, 1, 1], 1);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/algorithms/pairwise
,