-
Notifications
You must be signed in to change notification settings - Fork 18
Early developments for HW1 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| function CreateMovie(name, actors, about, options) { | ||
| 'use strict'; | ||
| this.options = options || {}; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. опции лучше не хранить целиком в this, а доставать из него все что нужно |
||
| 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() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а где использование? |
||
| '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) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return 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]; | ||
| }); | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
оберните все в модуль