Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created June 22, 2016 08:11
Show Gist options
  • Save tkssharma/83f02e829a35e346521f82e153f6797e to your computer and use it in GitHub Desktop.
Save tkssharma/83f02e829a35e346521f82e153f6797e to your computer and use it in GitHub Desktop.
(function () {
// We keep these variables private inside this closure scope
var myGrades = [93, 95, 88, 0, 55, 91];
var average = function() {
var total = myGrades.reduce(function(accumulator, item) {
return accumulator + item}, 0);
return 'Your average grade is ' + total / myGrades.length + '.';
}
var failing = function(){
var failingGrades = myGrades.filter(function(item) {
return item < 70;});
return 'You failed ' + failingGrades.length + ' times.';
}
console.log(failing());
}());
// ‘You failed 2 times.’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment