Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. ################################################################
  2. ##################### OOJS Stamps ##################
  3. ################################################################
  4.  
  5. var StampCollection = function(stamps){
  6. this.stamps = stamps
  7. }
  8.  
  9. StampCollection.prototype.stampNamed = function (stampName) {
  10. return this.stamps.find(function(stamp){
  11. return stamp.name === stampName;
  12. })
  13. }
  14.  
  15. StampCollection.prototype.stampsIssued = function (issueDate) {
  16. return this.stamps.filter(function(stamp){
  17. return stamp.issueDate === issueDate;
  18. })
  19. }
  20.  
  21. StampCollection.prototype.value = function() {
  22. return sum = this.stamps.reduce(function(total,stamp){
  23. return total + stamp.maximumAppraisal()
  24. }, 0)
  25. }
  26. ###########################################################################
  27. #################### OOJS Stamp Collection ##################
  28. ###########################################################################
  29. var StampCollection = function(stamps){
  30. this.stamps = stamps
  31. }
  32.  
  33. StampCollection.prototype.stampNamed = function (stampName) {
  34. return this.stamps.find(function(stamp){
  35. return stamp.name === stampName;
  36. })
  37. }
  38.  
  39. StampCollection.prototype.stampsIssued = function (issueDate) {
  40. return this.stamps.filter(function(stamp){
  41. return stamp.issueDate === issueDate;
  42. })
  43. }
  44.  
  45. StampCollection.prototype.value = function() {
  46. return sum = this.stamps.reduce(function(total,stamp){
  47. return total + stamp.maximumAppraisal()
  48. }, 0)
  49. }
  50.  
  51. ###########################################################################
  52. #################### OOJS Stamp Collection ##################
  53. ###########################################################################
  54. var Stamp = function(params) {
  55. this.name = params.name;
  56. this.issueDate = params.issueDate;
  57. this.appraisalValues = params.appraisalValues;
  58. }
  59.  
  60. Stamp.prototype.averageAppraisal = function() {
  61. var sum = this.appraisalValues.reduce(function(a,b){
  62. return a + b
  63. }, 0);
  64. return sum / this.appraisalValues.length;
  65. }
  66.  
  67. Stamp.prototype.maximumAppraisal = function() {
  68. var max = 0;
  69. for(var i = 0; i < this.appraisalValues.length; i++){
  70. if( this.appraisalValues[i] > max){
  71. max = this.appraisalValues[i]
  72. }
  73. }
  74. return max;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement