Created
June 15, 2017 16:59
-
-
Save betterkenly/6067d80d10aa629cae1bdad8bf8e4509 to your computer and use it in GitHub Desktop.
interview prop
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
// var cashAmount = function(value) { | |
// this.value = value; | |
// } | |
// cashAmount.prototype.totalInPennies = function() { | |
// return this.value * 100; | |
// } | |
// const cash = new cashAmount(10.50); | |
// cash.totalInPennies(); // -> 1050 | |
class CashAmount { | |
constructor(value) { | |
this.value = value; | |
this.pennies = this.value * 100; | |
} | |
totalInPennies (){ | |
return this.pennies; | |
} | |
addDoubleAmount(value) { | |
this.pennies = this.pennies + value * 100; | |
} | |
quantityOfEachDenomination () { | |
let result = {}; | |
let dollars = [100, 50, 20, 10, 5, 1]; | |
let cents = [50, 25, 10, 5, 1]; | |
return result; | |
} | |
toDouble() { | |
return this.pennies / 100; | |
} | |
toDoubleString() { | |
return (this.pennies / 100).toString(); | |
} | |
} | |
const cash = new CashAmount(10.50); | |
cash.addDoubleAmount(29.33); | |
cash.totalInPennies(); // -> 3983 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment