Jak obliczyć średnią tablicy w JavaScript
const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
TechWhizKid
const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
const avg = arr => {
const sum = arr.reduce((acc, cur) => acc + cur);
const average = sum/arr.length;
return average;
}
console.log(avg([1, 2, 3, 7, 8]));
var total = 0;
for(var i = 0; i < grades.length; i++) {
total += grades[i];
}
var avg = total / grades.length;