forked from speck-agency/Speck-Academy-2019-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (64 loc) · 1.71 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
let halls = [];
let hallId = 0;
function add(hallName) {
let hallObject = {
id: hallId,
name: hallName,
reservation: {
isReserved: false,
reservedFrom: null,
reservedUntil: null
}
}
halls.push(hallObject);
hallId++;
}
function remove(hallId) {
for (let i = 0; i < halls.length; i++) {
if (halls[i].id === hallId) {
halls.splice(i, 1);
}
}
}
function reservation(hallId, reservedFrom, reservedUntil) {
for (let i = 0; i < halls.length; i++) {
if (halls[i].id === hallId) {
halls[i].reservation.isReserved = true;
halls[i].reservation.reservedFrom = reservedFrom;
halls[i].reservation.reservedUntil = reservedUntil;
}
}
}
function checkReservation(hallId) {
let currentTimestamp = Date.now();
for (let i = 0; i < halls.length; i++) {
if (halls[i].id === hallId) {
if(halls[i].reservation.reservedUntil < currentTimestamp) {
halls[i].reservation.isReserved = false;
halls[i].reservation.reservedFrom = null;
halls[i].reservation.reservedUntil = null;
}
}
}
}
// empty halls array
console.log('Halls: ', halls);
add('Klub Kulture');
add('Hrvatski Dom');
add('Vladimir Nazor');
add('Galerija K1');
add('Ljudevit Modec');
// halls array after adding 5 objects
console.log('Halls: ', halls);
remove(3);
// halls array after removing object with id 3
console.log('Halls: ', halls);
remove(4);
// halls array after removing object with id 4
console.log('Halls: ', halls);
// reserve hall with id 2 from 04/01/2018 until 04/02/2018
reservation(2, 10142019, 10152019);
console.log('Halls: ', halls);
// check reservation for hall with id 2
checkReservation(2);
console.log('Halls: ', halls);