Skip to content

Instantly share code, notes, and snippets.

@hedgejanuary
Created July 30, 2018 14:44
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 hedgejanuary/538b1f434f687705f392ae03dc089401 to your computer and use it in GitHub Desktop.
Save hedgejanuary/538b1f434f687705f392ae03dc089401 to your computer and use it in GitHub Desktop.
This is the modified codes to calculate average score.
function averageScore(arr) {
var total = 0;
for (var i = 0; i < arr.length; i++) {
total += arr[i];
}
return total / arr.length;
}
// Another solution:
var averageScore = function (arr) {
var total = 0;
arr.forEach(function (elem) {
total += elem
});
return total / arr.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment