I am stuck with a problem and i don\'t know how to put this in a for loop. I need the hotizontal average of the next matrix:
1 2 3 4 5
5 4 3 2 1
3 2 1 4 5
This piece of code alerts the data structured in a table-like string.
var dArray = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [3, 2, 1, 4, 5]];
var str = '';
dArray.forEach(function(arr, index){
var average = arr.reduce(function(sum, item){ return sum + item; })/arr.length;
str += '\n Array ' + index + ': ' + arr.join(' ') + ' average: ' + average;
});
alert(str);