Skip to content

Instantly share code, notes, and snippets.

@nachocab
Created May 14, 2017 12:39
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 nachocab/5c056ef978351096bf72087cde608e6b to your computer and use it in GitHub Desktop.
Save nachocab/5c056ef978351096bf72087cde608e6b to your computer and use it in GitHub Desktop.
const stampit = require('stampit')
Grade = stampit({
init(percentage) {
this.percentage = percentage
this.grades = [
{letter: 'A', minimumPercentage: 0.9, passing: true},
{letter: 'B', minimumPercentage: 0.8, passing: true},
{letter: 'C', minimumPercentage: 0.7, passing: true},
{letter: 'D', minimumPercentage: 0.6, passing: true},
{letter: 'F', minimumPercentage: 0, passing: false}
]
this.grade = this.grade(percentage)
},
methods: {
passingGradeLetters() {
return this.grades.filter(x => x.passing).map(x => x.letter)
},
grade(percentage) {
debugger
return this.grades.find(x => percentage >= x.minimumPercentage)
},
letterGrade() {
return this.grade.letter
},
isPassing() {
return this.grade.passing
},
isImprovementFrom(grade) {
return this.isBetterThan(grade)
},
isBetterThan(grade) {
return this.percentage > grade.percentage
},
valueOf() {
return this.percentage
}
}
})
module.exports = Grade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment