Created
June 22, 2016 08:11
-
-
Save tkssharma/83f02e829a35e346521f82e153f6797e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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