How to fold the values of the elements of two arrays in js?

In the function arguments 2 in the array, I need to fold up their values and return to the function, tried using .replace but can't return the result of the calculation in the function, preferably in the normal way, because I just started to study this subject
June 10th 19 at 15:20
2 answers
June 10th 19 at 15:22
Solution
// Sum all elements
sumOfAllElements function(arr1, arr2) {
 sumOfArr1 = arr1.reduce((sum, el) => sum + el, 0);
 sumOfArr2 = arr2.reduce((sum, el) => sum + el, 0);

 return sumOfArr1 + sumOfArr2;
}

// Sum of vectors provided that their length is equal
sumOfVectors function(vec1, vec2) {
 var i = 0, result = [];

 while(i < vec1.length/2) {
 result[i] = vec1[i] + vec2[i];
 var j = vec1.length - 1 - i;
 result[j] = vec1[j] + vec2[j];

i++;
}

 return result;
}
June 10th 19 at 15:24

Find more questions by tags JavaScript