-
Notifications
You must be signed in to change notification settings - Fork 15
Петр Дюкин // js-task-3 #19
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 |
|---|---|---|
| @@ -1,20 +1,16 @@ | ||
| /** Задача 1 - Класс Time | ||
| Требуется написать класс времени - Time, который содержит: | ||
| 1.1. Поле с часами — hours (number) | ||
| 1.2. Поле с минутами — minutes (number) | ||
| 1.3. Прототип класса должен содержать метод сравнения isEarlier, | ||
| который принимает объект класса Time и возвращает true, | ||
| если переденное значение времени находится позже того, | ||
| которое содержится в экземпляре объекта, у которого вызван метод. | ||
| 1.4. Прототип класса должен содержать метод сравнения isLater, | ||
| который принимает объект класса Time и возвращает true, | ||
| если переденное значение времени находится раньше того, | ||
| которое содержится в экземпляре объекта, у которого вызван метод. | ||
| @constructor | ||
| @this {Time} | ||
| @param {number} hours - Час | ||
| @param {number} minutes - Минуты | ||
| */ | ||
| function Time(hours, minutes) { }; | ||
| function Time(hours, minutes) { | ||
| if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59) | ||
| throw "Неверный формат времени"; | ||
| this.hours = hours; | ||
| this.minutes = minutes; | ||
| } | ||
|
|
||
| module.exports.Time = Time; | ||
| Time.prototype.isEarlier = function (obj) { | ||
| return this.hours < obj.hours || this.hours === obj.hours && this.minutes < obj.minutes; | ||
| } | ||
|
|
||
| Time.prototype.isLater = function (obj) { | ||
| return this.hours > obj.hours || this.hours === obj.hours && this.minutes > obj.minutes; | ||
| } | ||
|
|
||
| module.exports.Time = Time; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,26 @@ | ||
| const { Time } = require('../task_1/index'); | ||
| /** Задача 2 - Класс Meeting | ||
| Требуется написать класс встречи - Meeting, который содержит: | ||
| 2.1. Поле c датой встречи (объект класса Date) | ||
| 2.2. Поле — время начала встречи (объект класса Time) | ||
| 2.3. Поле — время конца встречи (объект класса Time) | ||
| 2.4. Прототип класса должен содержать метод isMeetingInTimeRange, принимающий два аргумента: | ||
| Начало временного промежутка — объект класса Time | ||
| Конец временного промежутка — объект класса Time | ||
| Должен возвращать true, если встреча, у которой был вызван метод, | ||
| пересекает переданный временной промежутук | ||
| 2.5. Время начала встречи должно быть больше времени конца | ||
| 2.6. Встреча может быть назначана только в промежутке между 08:00 до 19:00 | ||
| @constructor | ||
| @this {Meeting} | ||
| @param {Date} meetingDate - Дата встречи | ||
| @param {Time} startTime - Время начала встречи | ||
| @param {Time} endTime - Время конца встречи | ||
| */ | ||
| function Meeting(meetingDate, startTime, endTime) { }; | ||
|
|
||
| module.exports.Meeting = Meeting; | ||
| function Meeting(meetingDate, startTime, endTime) { | ||
| if (startTime.hours > endTime.hours || startTime.hours === endTime.hours | ||
| && startTime.minutes >= endTime.minutes) | ||
| throw "Встреча не может начаться позже завершения"; | ||
| if (startTime.hours < 8 || endTime.hours >= 19 && endTime.minutes !== 0) | ||
| throw "Встреча может быть назначана только в промежутке между 08:00 до 19:00"; | ||
| this.meetingDate = meetingDate; | ||
| this.startTime = startTime; | ||
| this.endTime = endTime; | ||
| }; | ||
|
|
||
| Meeting.prototype.isMeetingInTimeRange = function (startTime, endTime) { | ||
| let isBetween = (start, item, end) => item >= start && item <= end; | ||
| let thisStartTime = this.startTime.hours * 60 + this.startTime.minutes; | ||
| let thisEndTime = this.endTime.hours * 60 + this.endTime.minutes; | ||
| startTime = startTime.hours * 60 + startTime.minutes; | ||
| endTime = endTime.hours * 60 + endTime.minutes; | ||
| return isBetween(thisStartTime, startTime, thisEndTime) || | ||
| isBetween(thisStartTime, endTime, thisEndTime) || | ||
| isBetween(startTime, thisStartTime, endTime) || | ||
| isBetween(startTime, thisEndTime, endTime); | ||
| } | ||
|
|
||
| module.exports.Meeting = Meeting; | ||
|
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. 1 балл |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,14 @@ | ||
| /** Задача 3 - Класс Vacation | ||
| Требуется написать класс отпуска - Vacation, который содержит: | ||
| 3.1. Дата начала (объект класса Date) | ||
| 3.2. Дата окончания (объект класса Time) | ||
| 3.3. Прототип класса должен содержать метод isDateInVacation, принимающий один аргумент — дату. | ||
| Должен возвращать true, если переданная дата, входит в промежуток отпуска. | ||
| 3.4. Дата окончания отпуска должна быть позже даты начала | ||
| @constructor | ||
| @this {Vacation} | ||
| @param {Date} vacationStartDate - Дата начала отпуска | ||
| @param {Date} vacationEndDate - Время конца отпуска | ||
| */ | ||
| function Vacation(vacationStartDate, vacationEndDate) { | ||
| if (typeof vacationStartDate === "undefined" || typeof vacationEndDate === "undefined") | ||
| throw "Необходимо передать оба аргумента"; | ||
| if (vacationStartDate - vacationEndDate >= 0) | ||
| throw "Дата окончания отпуска должна быть позже даты начала"; | ||
| this.vacationStartDate = vacationStartDate; | ||
| this.vacationEndDate = vacationEndDate; | ||
| }; | ||
|
|
||
| function Vacation(vacationStartDate, vacationEndDate) { }; | ||
| Vacation.prototype.isDateInVacation = function (date) { | ||
| return date - this.vacationStartDate >= 0 && this.vacationEndDate - date >= 0; | ||
| } | ||
|
|
||
| module.exports.Vacation = Vacation; | ||
| module.exports.Vacation = Vacation; | ||
|
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. 1 балл |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,9 @@ | ||
| const { Meeting } = require('../task_2/index'); | ||
| const { Vacation } = require('../task_3/index'); | ||
|
|
||
| /** Задача 4 - Класс Organaizer | ||
| Требуется написать класс органайзера - Organaizer, который содержит: | ||
| 4.1. Поле встреч — meetings (массив объектов класса Meeting) | ||
| 4.2. Поле отпусков — vacations (массив объектов класса Vacation) | ||
| function Organaizer(meetings, vacations) { | ||
| this.meetings = meetings; | ||
| this.vacations = vacations; | ||
| }; | ||
|
|
||
| @constructor | ||
| @this {Organaizer} | ||
| @param {Array<Meeting>} meetings - Массив встреч | ||
| @param {Array<Vacation>} vacations - Массив отпусков | ||
| */ | ||
|
|
||
| function Organaizer(meetings, vacations) { }; | ||
|
|
||
| module.exports.Organaizer = Organaizer; | ||
| module.exports.Organaizer = Organaizer; | ||
|
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. 1 балл |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| const { Organaizer } = require('../task_4/index'); | ||
|
|
||
| /* Задача 5 - Расширить прототип класса Organaizer следующими методами: | ||
| 5.1. addMeeting, принимающий — объект класса Meeting. | ||
| Результатом работы должно быть true и добавление объекта встречи в массив встреч, | ||
| если встреча успешно добавлена в органайзер и false в ином случае. | ||
| Встреча может быть добавлена, если: | ||
| В день встречи в органайзере нет отпуска | ||
| Время встречи не пересекается с какой-нибудь другой встречей в органайзере | ||
| 5.2. addVacation, принимающий — объект класса Vacation. | ||
| Результатом работы должно быть true и добавление объекта отпуска в массив отпусков, | ||
| если отпуск успешно добавлена в органайзер и false в ином случае. | ||
| Отпуск может быть добавлен, если: | ||
| Отпуск не попадает в промежуток другого отпуска | ||
| В промежуток отпуска не назначено никаких встреч | ||
| */ | ||
| Organaizer.prototype.addMeeting = function (meeting) { | ||
| for (let x of this.vacations) | ||
| if (x.isDateInVacation(meeting.meetingDate)) return false; | ||
| for (let x of this.meetings) | ||
| if (meeting.isMeetingInTimeRange(x.startTime, x.endTime) && | ||
| x.meetingDate.getDate() === meeting.meetingDate.getDate()) | ||
| return false; | ||
| this.meetings.push(meeting); | ||
| return true; | ||
| } | ||
|
|
||
| module.exports.Organaizer = Organaizer; | ||
| Organaizer.prototype.addVacation = function (vacation) { | ||
| for (let x of this.vacations) | ||
| if (x.isDateInVacation(vacation.vacationStartDate) || | ||
| x.isDateInVacation(vacation.vacationEndDate)) | ||
| return false; | ||
| for (let x of this.meetings) | ||
| if (vacation.isDateInVacation(x.meetingDate)) return false; | ||
| this.vacations.push(vacation); | ||
| return true; | ||
| } | ||
|
|
||
| module.exports.Organaizer = Organaizer; | ||
|
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. 1 балл |
||
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.
1 балл