forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expenses.js
39 lines (32 loc) · 1.13 KB
/
Expenses.js
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
const type = {
BREAKFAST: 1,
DINNER: 2,
CAR_RENTAL: 3,
};
function printReport(expenses) {
let total = 0;
let mealExpenses = 0;
process.stdout.write("Expenses " + new Date().toISOString().slice(0, 10) + "\n");
for (const expense of expenses) {
if (expense.type == type.DINNER || expense.type == type.BREAKFAST) {
mealExpenses += expense.amount;
}
let expenseName;
switch (expense.type) {
case type.DINNER:
expenseName = "Dinner";
break;
case type.BREAKFAST:
expenseName = "Breakfast";
break;
case type.CAR_RENTAL:
expenseName = "Car Rental";
break;
}
const mealOverExpensesMarker = ((expense.type == type.DINNER && expense.amount > 5000) || (expense.type == type.BREAKFAST && expense.amount > 1000)) ? "X" : " ";
process.stdout.write(expenseName + "\t" + expense.amount + "\t" + mealOverExpensesMarker);
total += expense.amount;
}
process.stdout.write("Meal expenses: " + mealExpenses);
process.stdout.write("Total expenses: " + total);
}