Tell us what’s happening:
How can I get the sum of Indices in element pairs? I am speaking about the array sumOfIndices.
Your code so far
function pairwise(arr, arg) {
let copyOfArr=arr;
let sumOfAddedNum=[];
let indeces=[];
let sumOfIndeces=[];
for(let i=0;i<copyOfArr.length;i++){
for(let j=0;j<arr.length;j++){
sumOfAddedNum.push(copyOfArr[i]+arr[j])
indeces.push(copyOfArr.indexOf(copyOfArr[i]))
indeces.push(arr.indexOf(arr[j]))
}
}
for(let i=0;i<sumOfAddedNum.length;i+=1){
sumOfIndeces.push(indeces[i]+indeces[i+1])
}
console.log(sumOfAddedNum,indeces,sumOfIndeces)
}
pairwise([1,4], 5);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
.
Challenge: Pairwise
Link to the challenge: