JavaScript Function To Calculate The Mean Value Of An Array Of Numbers

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

The content of this field is kept private and will not be shown publicly.
CAPTCHA
14 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.