-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.js
45 lines (38 loc) · 852 Bytes
/
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
var sc = [
{ product: 'bread', quantity: 6 },
{ product: 'pizza', quantity: 2 },
{ product: 'milk', quantity: 4 },
{ product: 'water', quantity: 10 },
];
var allow = {
lisbon: 5,
others: 7,
};
var description = '';
var check = function (city) {
if (sc.length > 0) {
var allowed;
if (city == 'lisbon') {
allowed = allow.lisbon;
} else {
allowed = allow.others;
}
for (item of sc) {
if (item.quantity > allowed) item.quantity = allowed;
}
}
};
check('lisbon');
console.log(sc);
var createDescription = function () {
var first = sc[0];
var p = first.product;
var q = first.quantity;
if (sc.length > 1) {
description = 'Order with ' + q + ' ' + p + ', etc...';
} else {
description = 'Order with ' + q + ' ' + p + '.';
}
};
createDescription();
console.log(description);