Skip to content

Instantly share code, notes, and snippets.

@macikokoro
Last active August 29, 2015 14:05
Show Gist options
  • Save macikokoro/153b981265474e6ee694 to your computer and use it in GitHub Desktop.
Save macikokoro/153b981265474e6ee694 to your computer and use it in GitHub Desktop.
Finding the mean with javaScript
//Find mean
var numArray = [2, 4, 4, 6, 8, 10];
var mean = 0;
for (var i = 0; i < numArray.length; i++) {
mean += numArray[i];
}
//logs the length of the array
console.log(numArray.length);
//logs the result of adding the intengers in the array
console.log(mean);
//logs the result mean of the array
console.log(mean/numArray.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment