I want my code to reduce the array to one number, which will be arithmetic average of all numbers in the array. I have written the code bellow but it’s not working. It sums first two numbers in the array, but then it doesnt and returns NaN. Can anyone help?
var pushed = [8.8,8.6,9,8.3];
var test;
var sum = 0;
var avg = 0;
test = pushed.reduce(function(a, b) {
sum = a + b;
console.log(sum);
avg = sum / pushed.length;
console.log(avg);
})