Skip to content

Левшин Михаил#18

Open
LevshinMisha wants to merge 8 commits intourfu-2016:masterfrom
LevshinMisha:master
Open

Левшин Михаил#18
LevshinMisha wants to merge 8 commits intourfu-2016:masterfrom
LevshinMisha:master

Conversation

@LevshinMisha
Copy link

No description provided.

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

robbery.js Outdated

Choose a reason for hiding this comment

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

это константа? посмотри, как в гайде рекомендуют называть константы.

Copy link
Author

Choose a reason for hiding this comment

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

Да Это по сути константа. Исправлю

robbery.js Outdated

Choose a reason for hiding this comment

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

зачем тебе этот массив? можно просто взять ключи словаря)

Copy link
Author

Choose a reason for hiding this comment

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

Для читаемости кода. daysDict.keys()[i] хуже чем daysArray[i]

Choose a reason for hiding this comment

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

по-моему, это не повод у всех словарей выделять ключи в массив) в конце концов, можешь уж список-то заново не создавать

robbery.js Outdated

Choose a reason for hiding this comment

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

числа нужно вынести в константы

robbery.js Outdated

Choose a reason for hiding this comment

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

в названии функции надо указывать, что она делает (то бишь глагол)

robbery.js Outdated
Copy link

@chipolinka chipolinka Oct 24, 2016

Choose a reason for hiding this comment

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

аналогично с timeInInterval

for (var i = 0; i < timeIntervalsArray.length; i++) {
if (timeIntervalsArray[i].timeInInterval(time)) {

return true;

Choose a reason for hiding this comment

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

а зачем тут отступ перед return?)

robbery.js Outdated

Choose a reason for hiding this comment

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

str.split(' ') наверное стоит вынести в переменную, раз часто используется

robbery.js Outdated

Choose a reason for hiding this comment

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

константы

robbery.js Outdated

Choose a reason for hiding this comment

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

по-моему, это не самое подходящее название переменной. мало ли чего там m может быть?) да и h тоже

robbery.js Outdated

Choose a reason for hiding this comment

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

кажется, тут есть дублирование... и константы, конечно.

robbery.js Outdated

Choose a reason for hiding this comment

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

ой, как много констант

robbery.js Outdated

Choose a reason for hiding this comment

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

goodTimeToHack = !timeInIntervals(newSchedule[gangster], i) ?

Copy link
Author

Choose a reason for hiding this comment

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

В случае если время неподходит первому, но подходит второму и третьему, то значение переменной будет true. Что не совсем то что нужно.

robbery.js Outdated

Choose a reason for hiding this comment

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

опять имя функции не по канону

robbery.js Outdated

Choose a reason for hiding this comment

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

просто интересно: а почему не >=? а именно отрицание от <?

Copy link
Author

Choose a reason for hiding this comment

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

Потому что я могу)

robbery.js Outdated

Choose a reason for hiding this comment

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

кажется, что это можно переписать в один if, ну или как-то более сокращенно

@chipolinka
Copy link

везде есть константы, которые надо вынести/переименовать.

@chipolinka
Copy link

🍅

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

robbery.js Outdated

Choose a reason for hiding this comment

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

лучше isTimeInIntervals

Choose a reason for hiding this comment

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

и аналогично во всех остальных местах)

robbery.js Outdated
Copy link

@chipolinka chipolinka Oct 24, 2016

Choose a reason for hiding this comment

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

меня смущает, что у тебя 4 раза встречается строка
strToIntDate(something) + bankTimezone * MINUTES_IN_HOUR
это никак не сделать поизящнее?
имею в виду DRY

robbery.js Outdated

Choose a reason for hiding this comment

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

иногда отступы всплывают в самых неожиданных местах. не рекомендую их ставить после фигурных скобочек (не только здесь, но и во всём коде). тут же нечего отделять логически?

Choose a reason for hiding this comment

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

а ещё название этой переменной предполагает, что в ней хранится время.

robbery.js Outdated

Choose a reason for hiding this comment

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

название функции следует начинать с глагола

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

robbery.js Outdated

Choose a reason for hiding this comment

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

можно сделать isGoodTimeToHack = !isTimeInIntervals(schedule[gangster], i)

Copy link
Author

Choose a reason for hiding this comment

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

Сделать, то можно. Только это не совсем правильно(я уже писал почему). Даже базовые тесты перестают проходить.

robbery.js Outdated

Choose a reason for hiding this comment

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

В данном while у тебя i не изменяется, кроме как увеличивается при каждой итерации? Почему бы тогда не сделать это циклом?

Copy link
Author

Choose a reason for hiding this comment

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

функция isGangsterNotBusy использует внешние переменные, одной из которой является переменная i. А так как функции объявлять внутри цикла нельзя(lint), то следовательно нужно объявить эту переменную и функцию ее использующую заранее. Я вижу выход из этой ситуации созданием функции, которая возвращает другую функцию. Попробую это сделать.

Copy link
Author

Choose a reason for hiding this comment

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

исправил даже изящнее чем сам предполагал)

robbery.js Outdated

Choose a reason for hiding this comment

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

А зачем ты это вынес в отдельную функцию? У тебя она вынесена далеко от этого места, да и содержит в себе 1 строчку...

Copy link
Author

Choose a reason for hiding this comment

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

В lint'е стоит ограничение, что нельзя создавать функции внутри цикла

robbery.js Outdated
Copy link

@chipolinka chipolinka Oct 28, 2016

Choose a reason for hiding this comment

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

Очень сложная строка. И давай у тебя весь парсинг будет вынесен в одно место?

robbery.js Outdated

Choose a reason for hiding this comment

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

Эту функцию можно разбить на наполнение нового расписания гангстерами и банком. И объединить результат как раз в этой функции.

robbery.js Outdated

Choose a reason for hiding this comment

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

Лучше создай новую переменную с соответствующим названием. А то не ясно, чем результат этой функции отличается от предыдущей. А так -- мне нравится организация кода 👍

return template;
if (!this.exists()) {

return '';

Choose a reason for hiding this comment

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

Кажется, тут лишний перенос строки

function getGangsterNames(schedule) {
var gangsterNames = [];
for (var gangsterName in schedule) {
if (schedule.hasOwnProperty(gangsterName)) {

Choose a reason for hiding this comment

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

Попробуй написать это как-то по-другому. Попроще :)

Copy link
Author

Choose a reason for hiding this comment

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

Ну если честно я не знаю как. https://learn.javascript.ru/object-for-in смотрел тут. hasOwnProperty для lint'a

Copy link

Choose a reason for hiding this comment

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

exports.isStar = true;

/**
* @param {Object} schedule – Расписание Банды

Choose a reason for hiding this comment

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

Почему удалил доки?

Copy link
Author

Choose a reason for hiding this comment

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

мешает

Choose a reason for hiding this comment

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

Но они же несут полезную информацию!

robbery.js Outdated

Choose a reason for hiding this comment

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

Если честно, на первый взгляд тут адище происходит. Слайсы не подойдут?

@chipolinka
Copy link

🍅

@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

robbery.js Outdated

Choose a reason for hiding this comment

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

Что это за название такое?)

robbery.js Outdated

Choose a reason for hiding this comment

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

В этой функции слишком часто используется arrayIntervals.length, лучше вынеси в отдельную переменную. Да и название покороче будет)

var gangstersIsNotBusy = true;
gangsterNames.forEach(function (gangster) {
if (isTimeInIntervals(schedule[gangster], time)) {
gangstersIsNotBusy = false;

Choose a reason for hiding this comment

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

Можно написать здесь return false;, а в конце функции -- return true;. Тогда без этой переменной обойдемся и меньше бегать по циклу будем)

Copy link
Author

Choose a reason for hiding this comment

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

К сожалению из forEach нельзя ничего возвращать(

@chipolinka
Copy link

В целом стало намного лучше, молодец. Исправь мелкие замечания, и я передаю тебя ментору.

@chipolinka
Copy link

🚀

@honest-hrundel honest-hrundel assigned mokhov and unassigned chipolinka Oct 28, 2016
@honest-hrundel
Copy link

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

@honest-hrundel
Copy link

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

Copy link

@mokhov mokhov left a comment

Choose a reason for hiding this comment

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

В данном решении очень много избыточного кода. Из-за этого его очень сложно читать. Хочу в ответном комментарии увидеть ответ на вопрос: как работает твой алгоритм?

exports.isStar = true;

var DAYS_INDEXES = { 'ПН': 0, 'ВТ': 1, 'СР': 2, 'ЧТ': 3, 'ПТ': 4, 'СБ': 5, 'ВС': 6 };
var DAYS_NAMES = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС'];
Copy link

Choose a reason for hiding this comment

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

Это ключи предыдущего объекта

};
}

function isTimeInIntervals(timeIntervalsArray, time) {
Copy link

Choose a reason for hiding this comment

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

Название читаю, а понять что она делает не могу

}

function strDateToDateObj(strDate) {
var strDateCopy = strDate.slice();
Copy link

Choose a reason for hiding this comment

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

Зачем это нужно?

function getGangsterNames(schedule) {
var gangsterNames = [];
for (var gangsterName in schedule) {
if (schedule.hasOwnProperty(gangsterName)) {
Copy link

Choose a reason for hiding this comment

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

this.start = start;
this.end = end;

this.getLength = function () {
Copy link

Choose a reason for hiding this comment

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

start и end известны на этапе создания объекта, почему length нужно вычислять, а нельзя сделать полем?

}

function createTimeIntervalWithShift(time, shift) {
return new TimeInterval(strDateToDateObj(time.from).intValue + shift,
Copy link

Choose a reason for hiding this comment

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

Это нечитаемый однострочник, нужно вынести аргументы TimeIntreval в читаемые переменные

strDateToDateObj(time.to).intValue + shift);
}

function simplifyTimesIntervals(timeIntervals, duration) {
Copy link

Choose a reason for hiding this comment

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

Название функции переводится как «Упростить временные интервалы». Я честно не понимаю что тут подразумевается


function simplifyTimesIntervals(timeIntervals, duration) {
var newTimeIntervals = [];
timeIntervals.forEach(function (timeInterval) {
Copy link

Choose a reason for hiding this comment

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

Для фильтрации массивов придумали специальную функцию https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

return newTimeIntervals;
}

function addOrChangeLastTimeInterval(arrayIntervals, timeToStartNewInterval) {
Copy link

Choose a reason for hiding this comment

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

Из названия функции абсолютно не понятно что она делает. И по коду я тоже ничего не понял

@mokhov
Copy link

mokhov commented Oct 30, 2016

🍅

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.

5 participants

Comments