-
Notifications
You must be signed in to change notification settings - Fork 77
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
Чернышёв Александр #42
base: master
Are you sure you want to change the base?
Conversation
🍅 Не пройден линтинг или базовые тесты |
🍏 Пройдено тестов 16 из 16 |
🍏 Пройдено тестов 19 из 19 |
@NiKiT0S обрати внимание решено доп. задание |
@@ -15,7 +15,132 @@ exports.isStar = true; | |||
* @returns {Object} | |||
*/ | |||
exports.getAppropriateMoment = function (schedule, duration, workingHours) { | |||
console.info(schedule, duration, workingHours); | |||
|
|||
var arrayOfAllTime = getAllArray(); |
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.
Массив всего времени? Стоит вложить больше семантики в название переменной
|
||
var arrayOfTimeRusty = getArrayOfTimes(schedule.Rusty); | ||
|
||
var arrayOfTimeLinus = getArrayOfTimes(schedule.Linus); |
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.
А если банда из 100 человек, 100 переменных создавать?
Смотри в сторону таких методов как map, reduce и т.п.
var arrayOfTimeLinus = getArrayOfTimes(schedule.Linus); | ||
var bankStartWork = getIntOfTimeWithMainUTC(workingHours.from); | ||
var bankFinishWork = getIntOfTimeWithMainUTC(workingHours.to); | ||
var array = arrayOfTimeDanny.concat(arrayOfTimeRusty).concat(arrayOfTimeLinus); |
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.
array - слишком абстрактно. Массив чего?
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]); |
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.
Что за число 1440 ? Стоит вынести в константы
return timeArray; | ||
} | ||
|
||
function mergeRange(array) { |
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.
Функция называется merge, но внутри еще и сортирует, надо разбить эти действия на 2
var resultArray = []; | ||
var prevStart = sortedArray[0][0]; | ||
var prevFinish = sortedArray[0][1]; | ||
for (var e = 1; e < sortedArray.length; e++) { |
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.
Для названия счетчика принято использовать i, j
} | ||
|
||
function getUTC(stringTime) { | ||
return Number(stringTime.substring(stringTime.length - 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.
А если будет +10 ? тогда вернет 0, неверно
return Number(stringTime.substring(stringTime.length - 1)); | ||
} | ||
|
||
function getIntOfTimeWithMainUTC(stringTime) { |
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.
Слишком замысловатое имя функции, getTimestamp подойдет лучше
|
||
function getIntOfTimeWithMainUTC(stringTime) { | ||
var mainUTC = getUTC(workingHours.from); | ||
if (stringTime.length === 7) { |
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.
Проверка длины строки не лучшая идея, легко описать случаи, когда программа поведет себя неправильно
var day = 0; | ||
if (stringTime.substring(0, 2) === 'ВТ') { | ||
day = 1440; | ||
} else if (stringTime.substring(0, 2) === 'СР') { |
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.
Для вычленения частей даты проще написать одно регулярное выражение, чем каждый раз искать substring.
Попробуй реализовать через него
if (stringTime.substring(0, 2) === 'ВТ') { | ||
day = 1440; | ||
} else if (stringTime.substring(0, 2) === 'СР') { | ||
day = 2880; |
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.
Еще магические числа. Количество минут в дне можно вынести в константы, так будет семантичнее
if (!this.exists()) { | ||
return ''; | ||
} | ||
var DD = Math.floor(answer / 1440); |
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.
DD - как будто константа, можно же назвать просто days, MM - minutes, HH - hours
day = 'ВТ'; | ||
} else if (DD === 2) { | ||
day = 'СР'; | ||
} |
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.
days = ['ПН', 'ВТ', 'CР'];
day = days[DD];
Много замечаний к именованию переменных и функций, пытайся вложить больше смысла в названия. |
🍅 |
🍅 Пройдено тестов 15 из 19 |
🍅 Пройдено тестов 15 из 19 |
🍏 Пройдено тестов 19 из 19 |
@NiKiT0S обрати внимание решено доп. задание |
@@ -15,7 +15,140 @@ exports.isStar = true; | |||
* @returns {Object} | |||
*/ | |||
exports.getAppropriateMoment = function (schedule, duration, workingHours) { | |||
console.info(schedule, duration, workingHours); | |||
|
|||
var minPerDay = 1440; |
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.
Это константы, их нужно вынести из функции и именовать согласно принятым стандартам CONST_HUNDRED = 100
|
||
var answerArray = getAnswerArray(); | ||
|
||
var answer = answerArray.length === 0 ? -1 : answerArray[0][0]; |
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.
Странное название переменной. Если есть ответ зачем что-то еще искать?)
|
||
var tryLaterCounter = 0; | ||
|
||
function getArrOfGoodTime() { |
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.
Хотелось бы увидеть комментарии к каждой функции, что на входе и что она делает со своими входными данными (т.е. этот комментарий относится ко всем функциям, а не конкретно к этой)
return []; | ||
} | ||
var resultArray = []; | ||
var arr = answerArray; |
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.
Зачем answerArray
пихать в arr
|
||
var arrIntervals = []; | ||
|
||
for (var friend in schedule) { |
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.
Используй Object.keys(schedule)
там встроенный hasOwnProperty
|
||
var bankStartWork = getTimestamp(workingHours.from); | ||
var bankFinishWork = getTimestamp(workingHours.to); | ||
arrIntervals.push([0, bankStartWork], [bankFinishWork, bankStartWork + minPerDay], |
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.
А если банк начинает работу с 0 часов? тогда в busyIntervals
появится [0, 0]
. В этом случае программа отработает правильно?
function getAnswerArray() { | ||
var busyIntervals = getBusyIntervals(); | ||
|
||
var sortAndMergeArray = mergeRange(busyIntervals); |
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.
просто mergedArray
} | ||
|
||
function sortArray(array) { | ||
return array.sort(function compareArrays(a, b) { |
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.
Необязаттельно давать этой функции имя compareArrays
, эту функцию ты по имени не вызываешь, она вполне может быть анонимной
|
||
function getTimestamp(stringTime) { | ||
var mainUTC = getUTC(workingHours.from); | ||
if (stringTime.length === 7) { |
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.
Длина строки времени работы банка может быть равна 8
, в случае если сдвиг больше +9
Для вычленения минут/часов/дней я бы использовал regexp
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.
Кстати я обращал внимание на это еще в первом review
|
||
return m + minPerHour * h; | ||
} | ||
var day = 0; |
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.
var DAYS = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'CБ', 'ВС'];
var day = DAYS[stringTime.substring(0, 2)];
Итого 2 строки вместо 6
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.
И это тоже я уже писал
var hours = Math.floor((answer - day * minPerDay) / minPerHour); | ||
var minutes = answer - day * minPerDay - hours * minPerHour; | ||
|
||
var days = ['ПН', 'ВТ', 'СР']; |
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.
В константы можно вынести
🍅 |
No description provided.