Skip to content

Instantly share code, notes, and snippets.

@miker-mcd
Forked from markjnkim/OOJS
Created September 12, 2017 22:40
Show Gist options
  • Save miker-mcd/ead75bfa8c893194bfcf9d8e3f824089 to your computer and use it in GitHub Desktop.
Save miker-mcd/ead75bfa8c893194bfcf9d8e3f824089 to your computer and use it in GitHub Desktop.
OOJS prototypes
################################################################
##################### OOJS Stamps ##################
################################################################
var StampCollection = function(stamps){
this.stamps = stamps
}
StampCollection.prototype.stampNamed = function (stampName) {
return this.stamps.find(function(stamp){
return stamp.name === stampName;
})
}
StampCollection.prototype.stampsIssued = function (issueDate) {
return this.stamps.filter(function(stamp){
return stamp.issueDate === issueDate;
})
}
StampCollection.prototype.value = function() {
return sum = this.stamps.reduce(function(total,stamp){
return total + stamp.maximumAppraisal()
}, 0)
}
###########################################################################
#################### OOJS Stamp Collection ##################
###########################################################################
var StampCollection = function(stamps){
this.stamps = stamps
}
StampCollection.prototype.stampNamed = function (stampName) {
return this.stamps.find(function(stamp){
return stamp.name === stampName;
})
}
StampCollection.prototype.stampsIssued = function (issueDate) {
return this.stamps.filter(function(stamp){
return stamp.issueDate === issueDate;
})
}
StampCollection.prototype.value = function() {
return sum = this.stamps.reduce(function(total,stamp){
return total + stamp.maximumAppraisal()
}, 0)
}
###########################################################################
#################### OOJS Stamp Collection ##################
###########################################################################
var Stamp = function(params) {
this.name = params.name;
this.issueDate = params.issueDate;
this.appraisalValues = params.appraisalValues;
}
Stamp.prototype.averageAppraisal = function() {
var sum = this.appraisalValues.reduce(function(a,b){
return a + b
}, 0);
return sum / this.appraisalValues.length;
}
Stamp.prototype.maximumAppraisal = function() {
var max = 0;
for(var i = 0; i < this.appraisalValues.length; i++){
if( this.appraisalValues[i] > max){
max = this.appraisalValues[i]
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment