Skip to content

Instantly share code, notes, and snippets.

@edysegura
Created June 9, 2016 12:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save edysegura/4ffbf0cf6e9f0bd48586c9d03ee37165 to your computer and use it in GitHub Desktop.
Save edysegura/4ffbf0cf6e9f0bd48586c9d03ee37165 to your computer and use it in GitHub Desktop.
[JS] Using reduce to calculate average
var scores = [1, 4, 6, 8];
var result = scores.reduce((total, score) => total + score) / scores.length;
console.log(result); // 4.75
@abhishek-1994
Copy link

var scores = [1, 4, 6, 8];
var result = scores.reduce((total, score) => total + score) / scores.length;
console.log(result); // 4.75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment