Created
June 15, 2017 16:58
-
-
Save OneCent01/eb1596ad48535dbe40a30ed357714c52 to your computer and use it in GitHub Desktop.
This file contains 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
class CashAmount { | |
constructor(amount) { | |
this.amount = amount; | |
} | |
} | |
CashAmount.prototype.totalInPennies = function() { | |
var pennies = this.amount * 100; | |
return pennies; | |
}; | |
CashAmount.prototype.addDoubleAmount = function(doubleAmount) { | |
this.amount = this.amount * 100; | |
this.amount += (doubleAmount * 100); | |
this.amount /= 100; | |
return this.amount; | |
}; | |
CashAmount.prototype.quantityOfEachDenomination = function() { | |
var denominations = [ | |
'thousands', | |
'hundreds', | |
'fifties', | |
'twenties', | |
'tens', | |
'fives', | |
'ones', | |
'quarters', | |
'dimes', | |
'nickels', | |
'pennies' | |
]; | |
var amountArray = (this.amount * 100 + '').split(''); | |
var storage = {}; | |
while(amountArray.length > 0) { | |
var popNumber = amountArray.pop(); | |
var popString = denominations.pop(); | |
storage[popString] = popNumber; | |
} | |
return storage; | |
}; | |
CashAmount.prototype.toDouble = function() { | |
return this.amount; | |
}; | |
CashAmount.prototype.toDoubleString = function() { | |
return this.amount.toFixed(2); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment