Skip to content

Чернышёв Александр#42

Open
aleksch wants to merge 6 commits intourfu-2016:masterfrom
aleksch:master
Open

Чернышёв Александр#42
aleksch wants to merge 6 commits intourfu-2016:masterfrom
aleksch:master

Conversation

@aleksch
Copy link
Copy Markdown

@aleksch aleksch commented Oct 25, 2016

No description provided.

@honest-hrundel honest-hrundel changed the title Александр Чернышев Чернышёв Александр Oct 25, 2016
@honest-hrundel
Copy link
Copy Markdown

🍅 Не пройден линтинг или базовые тесты

@honest-hrundel
Copy link
Copy Markdown

🍏 Пройдено тестов 16 из 16

@honest-hrundel
Copy link
Copy Markdown

🍏 Пройдено тестов 19 из 19

@honest-hrundel
Copy link
Copy Markdown

@NiKiT0S обрати внимание решено доп. задание

Comment thread robbery.js Outdated
exports.getAppropriateMoment = function (schedule, duration, workingHours) {
console.info(schedule, duration, workingHours);

var arrayOfAllTime = getAllArray();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Массив всего времени? Стоит вложить больше семантики в название переменной

Comment thread robbery.js Outdated

var arrayOfTimeRusty = getArrayOfTimes(schedule.Rusty);

var arrayOfTimeLinus = getArrayOfTimes(schedule.Linus);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А если банда из 100 человек, 100 переменных создавать?
Смотри в сторону таких методов как map, reduce и т.п.

Comment thread robbery.js Outdated
var arrayOfTimeLinus = getArrayOfTimes(schedule.Linus);
var bankStartWork = getIntOfTimeWithMainUTC(workingHours.from);
var bankFinishWork = getIntOfTimeWithMainUTC(workingHours.to);
var array = arrayOfTimeDanny.concat(arrayOfTimeRusty).concat(arrayOfTimeLinus);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

array - слишком абстрактно. Массив чего?

Comment thread robbery.js Outdated
var array = arrayOfTimeDanny.concat(arrayOfTimeRusty).concat(arrayOfTimeLinus);
array.push([0, bankStartWork], [bankFinishWork, bankStartWork + 1440],
[bankFinishWork + 1440, bankStartWork + 1440 * 2],
[bankFinishWork + 1440 * 2, 1440 * 3 - 1]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Что за число 1440 ? Стоит вынести в константы

Comment thread robbery.js Outdated
return timeArray;
}

function mergeRange(array) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Функция называется merge, но внутри еще и сортирует, надо разбить эти действия на 2

Comment thread robbery.js Outdated
var resultArray = [];
var prevStart = sortedArray[0][0];
var prevFinish = sortedArray[0][1];
for (var e = 1; e < sortedArray.length; e++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Для названия счетчика принято использовать i, j

Comment thread robbery.js
}

function getUTC(stringTime) {
return Number(stringTime.substring(stringTime.length - 1));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А если будет +10 ? тогда вернет 0, неверно

Comment thread robbery.js Outdated
return Number(stringTime.substring(stringTime.length - 1));
}

function getIntOfTimeWithMainUTC(stringTime) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Слишком замысловатое имя функции, getTimestamp подойдет лучше

Comment thread robbery.js

function getIntOfTimeWithMainUTC(stringTime) {
var mainUTC = getUTC(workingHours.from);
if (stringTime.length === 7) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Проверка длины строки не лучшая идея, легко описать случаи, когда программа поведет себя неправильно

Comment thread robbery.js
var day = 0;
if (stringTime.substring(0, 2) === 'ВТ') {
day = 1440;
} else if (stringTime.substring(0, 2) === 'СР') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Для вычленения частей даты проще написать одно регулярное выражение, чем каждый раз искать substring.
Попробуй реализовать через него

Comment thread robbery.js Outdated
if (stringTime.substring(0, 2) === 'ВТ') {
day = 1440;
} else if (stringTime.substring(0, 2) === 'СР') {
day = 2880;
Copy link
Copy Markdown

@ninjagrizzly ninjagrizzly Oct 27, 2016

Choose a reason for hiding this comment

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

Еще магические числа. Количество минут в дне можно вынести в константы, так будет семантичнее

Comment thread robbery.js Outdated
if (!this.exists()) {
return '';
}
var DD = Math.floor(answer / 1440);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DD - как будто константа, можно же назвать просто days, MM - minutes, HH - hours

Comment thread robbery.js Outdated
day = 'ВТ';
} else if (DD === 2) {
day = 'СР';
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

days = ['ПН', 'ВТ', 'CР'];
day = days[DD];

@ninjagrizzly
Copy link
Copy Markdown

Много замечаний к именованию переменных и функций, пытайся вложить больше смысла в названия.
Используй методы forEach, map, reduce они так и напрашиваются быть использованными в этой задаче
Хорошо бы снабдить функции хотя бы краткими комментариями (что на входе, что происходит внутри)

@ninjagrizzly
Copy link
Copy Markdown

🍅

@honest-hrundel
Copy link
Copy Markdown

🍅 Пройдено тестов 15 из 19

@honest-hrundel
Copy link
Copy Markdown

🍅 Пройдено тестов 15 из 19

@honest-hrundel
Copy link
Copy Markdown

🍏 Пройдено тестов 19 из 19

@honest-hrundel
Copy link
Copy Markdown

@NiKiT0S обрати внимание решено доп. задание

Comment thread robbery.js
exports.getAppropriateMoment = function (schedule, duration, workingHours) {
console.info(schedule, duration, workingHours);

var minPerDay = 1440;
Copy link
Copy Markdown

@ninjagrizzly ninjagrizzly Nov 1, 2016

Choose a reason for hiding this comment

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

Это константы, их нужно вынести из функции и именовать согласно принятым стандартам CONST_HUNDRED = 100

Comment thread robbery.js

var answerArray = getAnswerArray();

var answer = answerArray.length === 0 ? -1 : answerArray[0][0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Странное название переменной. Если есть ответ зачем что-то еще искать?)

Comment thread robbery.js

var tryLaterCounter = 0;

function getArrOfGoodTime() {
Copy link
Copy Markdown

@ninjagrizzly ninjagrizzly Nov 1, 2016

Choose a reason for hiding this comment

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

Хотелось бы увидеть комментарии к каждой функции, что на входе и что она делает со своими входными данными (т.е. этот комментарий относится ко всем функциям, а не конкретно к этой)

Comment thread robbery.js
return [];
}
var resultArray = [];
var arr = answerArray;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Зачем answerArray пихать в arr

Comment thread robbery.js

var arrIntervals = [];

for (var friend in schedule) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Используй Object.keys(schedule) там встроенный hasOwnProperty

Comment thread robbery.js

var bankStartWork = getTimestamp(workingHours.from);
var bankFinishWork = getTimestamp(workingHours.to);
arrIntervals.push([0, bankStartWork], [bankFinishWork, bankStartWork + minPerDay],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А если банк начинает работу с 0 часов? тогда в busyIntervals появится [0, 0]. В этом случае программа отработает правильно?

Comment thread robbery.js
function getAnswerArray() {
var busyIntervals = getBusyIntervals();

var sortAndMergeArray = mergeRange(busyIntervals);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

просто mergedArray

Comment thread robbery.js
}

function sortArray(array) {
return array.sort(function compareArrays(a, b) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Необязаттельно давать этой функции имя compareArrays, эту функцию ты по имени не вызываешь, она вполне может быть анонимной

Comment thread robbery.js

function getTimestamp(stringTime) {
var mainUTC = getUTC(workingHours.from);
if (stringTime.length === 7) {
Copy link
Copy Markdown

@ninjagrizzly ninjagrizzly Nov 1, 2016

Choose a reason for hiding this comment

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

Длина строки времени работы банка может быть равна 8, в случае если сдвиг больше +9
Для вычленения минут/часов/дней я бы использовал regexp

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Кстати я обращал внимание на это еще в первом review

Comment thread robbery.js

return m + minPerHour * h;
}
var day = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

var DAYS = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'CБ', 'ВС'];
var day = DAYS[stringTime.substring(0, 2)];

Итого 2 строки вместо 6

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

И это тоже я уже писал

Comment thread robbery.js
var hours = Math.floor((answer - day * minPerDay) / minPerHour);
var minutes = answer - day * minPerDay - hours * minPerHour;

var days = ['ПН', 'ВТ', 'СР'];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В константы можно вынести

@ninjagrizzly
Copy link
Copy Markdown

🍅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants