Skip to content

Instantly share code, notes, and snippets.

@AgtLucas
Forked from edysegura/array-reduce.js
Created November 15, 2017 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgtLucas/8e7ffbdcf5875f0061c263aef1b988a0 to your computer and use it in GitHub Desktop.
Save AgtLucas/8e7ffbdcf5875f0061c263aef1b988a0 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment