Created
August 10, 2021 05:15
-
-
Save dobeerman/3b4692fbe60abd89db39e8ba5f0c513b to your computer and use it in GitHub Desktop.
Revisions
-
dobeerman created this gist
Aug 10, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ /** * Say, a customer requires $247 from an ATM machine. * What is the combination of bank notes ($100, $50, $20, $10, $5, $1) * that satisfies that request? */ class RequestBill { private pairs: number[][]; constructor(private amount: number) { this.pairs = []; } get(bill: number) { var count = Math.floor(this.amount / bill); this.amount -= count * bill; this.pairs.push([count, bill]) return this; } getPairs() { return this.pairs } } const request = new RequestBill(378); request.get(100).get(50).get(20).get(10).get(5).get(1); console.log(request.getPairs())