JavaScript Function To Calculate The Mean Value Of An Array Of Numbers
4th February 2023
function mean(numbers) {
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
return sum / numbers.length;
}
let numbers = [1, 2, 3, 4, 5];
let meanValue = mean(numbers);
console.log(meanValue); // Output: 3
Add new comment