I want to combine two array to sum up each element or the array up and return the result array.I AM PRACTICING HIGH ORDER FUNCTION, and although this can be easily solved, I am more inclined to seek advice for higher order function suggestions. something like this:
var a=[1,2,3], b=[7,8,9];
func(a,b);// should return [8,10,12];
I need to do it more elegantly using high order functions, so cannot use a a simple loop to add each elements up. I know Map/Reduce function can apply to 1D array, but how about between the arrays? any elegant implementations?
My effort:
var arr=[a,b];
var toReturn=arr[0].map(function(_, i) {
return arr.reduce(function(max, row) {
return max+row[i];
}, 0);
});
I know it is more complicated than it should be, but i am trying to learn higher order function that's it.