-
-
Save miker-mcd/ead75bfa8c893194bfcf9d8e3f824089 to your computer and use it in GitHub Desktop.
OOJS prototypes
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
| ################################################################ | |
| ##################### 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