-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProblem 7
More file actions
42 lines (40 loc) · 705 Bytes
/
Problem 7
File metadata and controls
42 lines (40 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function bills(cost) {
var breakdown = {};
if (cost / 100 >= 0.96) {
breakdown[100] = Math.floor(cost / 100);
cost = cost % 100;
if (cost > 95) {
breakdown[100] += 1;
return breakdown;
}
}
if (cost / 50 >= 0.92){
breakdown[50] = 1;
cost = cost - 50;
}
if (cost / 20 >= 1){
breakdown[20] = Math.floor(cost / 20);
cost = cost % 20;
if (cost > 15) {
breakdown[20] += 1;
return breakdown;
}
}
if (cost / 10 >= 1){
breakdown[10] = 1;
cost = cost - 10;
if (cost > 5) {
delete breakdown[10];
breakdown[20] = 1;
return breakdown;
}
}
if (cost > 5) {
breakdown[10] = 1;
return breakdown;
}
if (cost > 0){
breakdown[5] = 1;
}
return breakdown;
}