Skip to content

Задание второй лекции #3

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*Возвращает объект Event
*@param {Number | Date} start Начало события
*@param {Number | Date} end Конец события
*@param {String} name Имя события
*@param {String} place Место проведения
*@param {String} repeat["Нет", "Каждый день", "Каждую неделю", "Раз в 2 недели", "Каждый месяц", "Каждый год"] Повтор
*@param {String} member[] Участники
*@param {String} reminder["В момент события", "За 5 минут", "За 15 минут", "За 30 минут", "За 1 час", "За 2 часа"] Напоминание
*@param {Number} gps[longitude, latitude] GPS координаты места
*@param {String} note Заметки
*@example
*Event(new Date('2011-10-10T14:48:00'),
* new Date('2011-10-10T15:48:00'),
* "Деловая встреча",
* "г. Екатеринбург, ул. Уральская, д. 67",
* new []("Каждый день"),
* new []("Беднева Дарья", "Петрова Марина", "Беляева Анастасия"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

так не получится new []("Беднева Дарья", "Петрова Марина", "Беляева Анастасия") можно просто ["Беднева Дарья", "Петрова Марина", "Беляева Анастасия"]

https://speakerdeck.com/u/azproduction/p/2-liektsiia?slide=30

* new [](За 1 час),
* new [](56.855636, 60.636671),
* "Принести с собой ноутбук.")
*
*@return {Object}
*/
function Event(start, end, name, place, repeat, member, reminder, gps, note) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У функции много аргументов подумай как можно уменьшить их число.

"use strict";
return {
"start": +start,
"end": +end,
"name": name || "Событие",
"place": place || "Город, улица, дом",
"repeat": repeat,
"member": member[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Будет ошибка. Можно проверить просто тип параметра. member instanceof Array ? member : [] или сделать данный парамтр обязательным и выбросить исключение.

На тип данный можно проверить поэлементно typeof gps[0] === "number" ...

На вхождение в "словарь" можно проверить так

var availableRemainders = {
    "В момент события": true, 
    "За 5 минут": true
};

reminder = availableRemainders[reminder] ? reminder : void 0

"reminder": reminder,
"gps": gps,
"note": note || "Заметки"
};
}
38 changes: 38 additions & 0 deletions event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*���������� ������ Event
*@param {Number | Date} start ������ �������
*@param {Number | Date} end ����� �������
*@param {String} name ��� �������
*@param {String} place ����� ����������
*@param {String} repeat["���", "������ ����", "������ ������", "��� � 2 ������", "������ �����", "������ ���"] ������
*@param {String} member[] ���������
*@param {String} reminder["� ������ �������", "�� 5 �����", "�� 15 �����", "�� 30 �����", "�� 1 ���", "�� 2 ����"] �����������
*@param {Number} gps[longitude, latitude] GPS ���������� �����
*@param {String} note �������
*@example
*Event(new Date('2011-10-10T14:48:00'),
* new Date('2011-10-10T15:48:00'),
* "������� �������",
* "�. ������������, ��. ���������, �. 67",
* new []("������ ����"),
* new []("������� �����", "������� ������", "������� ���������"),
* new [](�� 1 ���),
* new [](56.855636, 60.636671),
* "�������� � ����� �������.")
*
*@return {Object}
*/
function Event(start, end, name, place, repeat, member, reminder, gps, note) {
"use strict";
return {
"start": +start,
"end": +end,
"name": name || "�������",
"place": place || "�����, �����, ���",
"repeat": repeat,
"member": member[],
"reminder": reminder,
"gps": gps,
"note": note || "�������"
};
}