Skip to content

Commit 30193c9

Browse files
authored
Create README.md
1 parent f940b24 commit 30193c9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cash-register/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# cash-register
2+
3+
## Concept
4+
Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the third argument.
5+
6+
cid is a 2D array listing available currency.
7+
8+
The `checkCashRegister()` function should always return an object with a status key and a change key.
9+
10+
Return `{status: "INSUFFICIENT_FUNDS", change: []}` if cash-in-drawer is less than the change due, or if you cannot return the exact change.
11+
12+
Return `{status: "CLOSED", change: [...]}` with cash-in-drawer as the value for the key change if it is equal to the change due.
13+
14+
Otherwise, return `{status: "OPEN", change: [...]}`, with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.
15+
16+
## Solution
17+
To sovle this problem we use a greedy algorithm. Starting from the largest value, we pass through the cid array and check if we can subtract this value from the changeValue and have a positive outcome.
18+
19+
## Programming
20+
To successfully add or subtract two decimal numbers it is necessary to use [Math.round()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round).

0 commit comments

Comments
 (0)