-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.js
64 lines (56 loc) · 1.51 KB
/
clean.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var budget = [
{ value: 250, description: 'Sold old TV 📺', user: 'jonas' },
{ value: -45, description: 'Groceries 🥑', user: 'jonas' },
{ value: 3500, description: 'Monthly salary 👩💻', user: 'jonas' },
{ value: 300, description: 'Freelancing 👩💻', user: 'jonas' },
{ value: -1100, description: 'New iPhone 📱', user: 'jonas' },
{ value: -20, description: 'Candy 🍭', user: 'matilda' },
{ value: -125, description: 'Toys 🚂', user: 'matilda' },
{ value: -1800, description: 'New Laptop 💻', user: 'jonas' },
];
var limits = {
jonas: 1500,
matilda: 100,
};
var add = function (value, description, user) {
if (!user) user = 'jonas';
user = user.toLowerCase();
var lim;
if (limits[user]) {
lim = limits[user];
} else {
lim = 0;
}
if (value <= lim) {
budget.push({ value: -value, description: description, user: user });
}
};
add(10, 'Pizza 🍕');
add(100, 'Going to movies 🍿', 'Matilda');
add(200, 'Stuff', 'Jay');
console.log(budget);
var check = function () {
for (var el of budget) {
var lim;
if (limits[el.user]) {
lim = limits[el.user];
} else {
lim = 0;
}
if (el.value < -lim) {
el.flag = 'limit';
}
}
};
check();
console.log(budget);
var bigExpenses = function (limit) {
var output = '';
for (var el of budget) {
if (el.value <= -limit) {
output += el.description.slice(-2) + ' / '; // Emojis are 2 chars
}
}
output = output.slice(0, -2); // Remove last '/ '
console.log(output);
};