-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathkinobistro.js
More file actions
101 lines (87 loc) · 3.2 KB
/
Copy pathkinobistro.js
File metadata and controls
101 lines (87 loc) · 3.2 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function CreateMovie(name, actors, about, options) {
'use strict';
this.options = options || {};
this.name = name;
this.actors = actors;
this.about = about;
this.rating = options.rating || 0;
}
function CreateCinema(name, timetable, location, options) {
'use strict';
this.options = options || {};
this.name = name;
this.timetable = timetable;
this.location = location;
}
function CreateUser(name, location) {
'use strict';
this.name = name;
this.location = location;
}
function Base() {
'use strict';
function randActors(actors) {
var newActors = [],
i = 0;
for (i = 0; i < 4; i += 1) {
newActors.push(actors[Math.floor(Math.random() * actors.length)]);
}
return newActors;
}
function randTimetables(movies) {
var timetable = [],
i = 0;
for (i = 0; i < 5; i += 1) {
timetable.push({hour: (12 + i * 2).toString(), minute: '00', movie: movies[Math.floor(Math.random() * movies.length)]});
}
return timetable;
}
var actors = ['Jude Low', 'Kameron Diaz', 'Brus Willes', 'Will Smith', 'Robert Douny jr.',
'Johny Dep', 'Vin Dizel', 'Jason Stathem', 'Dwane Johnson', 'Arnold Shwarzneger',
'Kianu Rivz', 'Silvestr Stalone', 'Michel Rodrigez'],
movies = ['Chappie', 'Focus', 'Duxless 2',
'Green Planet', 'Zolushka', 'Mezhdu delom', 'Forsazh 7', 'Proklyatie'].map(function (name) {
return new CreateMovie(name, randActors(actors), 'about movie', {rating: Math.random() * 10});
}),
cinemas = ['Kosmos', 'Kolizey', 'Salut', 'Titanic Cinema', 'Rolics', 'Premier Zal'].map(function (name) {
return new CreateCinema(name, randTimetables(movies), {x: Math.random() * 100, y: Math.random() * 100});
}),
user = new CreateUser('Stanislav', {x: Math.random() * 100, y: Math.random() * 100});
this.movies = movies;
this.cinemas = cinemas;
this.user = user;
this.filterByMovieName = function (movies, name) {
return movies.filter(function (movie) {
return movie.name.toLowerCase().includes(name.toLowerCase());
});
};
this.filterMoviesByRating = function (movies, rating) {
return movies.filter(function (movie) {
return movie.rating >= rating;
});
};
this.filterCinemasByMovie = function (cinemas, movie) {
return cinemas.filter(function (cinema) {
return cinema.timetable.some(function (session) {
if (session.movie.name === movie.name) {
return true;
}
return false;
});
});
};
this.sortCinemasByLocation = function (cinemas, location) {
var map = cinemas.map(function (cinema, i) {
return {
index: i,
value: Math.sqrt(Math.pow(cinema.location.x - location.x, 2) + Math.pow(cinema.location.y - location.y, 2))
};
});
map.sort(function (a, b) {
return a.value - b.value;
});
return map.map(function (cinema) {
return cinemas[cinema.index];
});
};
}