Comment calculer la moyenne du tableau en 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;
const sum = times.reduce((a, b) => a + b, 0);
const avg = (sum / times.length) || 0;
console.log(`The sum is: ${sum}. The average is: ${avg}.`);
class Avg {
constructor() {}
static average(array) {
var total = 0;
var count = 0;
jQuery.each(array, function(index, value) {
total += value;
count++;
});
return total / count;
}
}
var arry = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
console.log(Avg.average(arry));
public class ArrayAverage {
public static void main(String[] args) {
double[] numbers = new double[5]; //double[] arr = {6.7, 8.9, 2.7, 6, 1};
numbers[0] = 6.7;
numbers[1] = 8.9;
numbers[2] = 2.7;
numbers[3] = 6;
numbers[4] = 1;
double sum = 0;
for (int i = 0; i < numbers.length; i++) {
sum = sum + numbers[i];
}
System.out.println(sum);
}
}