Skip to content

Conversation

@PAVLUXAN
Copy link
Contributor

@PAVLUXAN PAVLUXAN commented May 27, 2025

@keksobot keksobot changed the title feat:create functions Нужно больше функций May 27, 2025
keksobot pushed a commit that referenced this pull request May 27, 2025
@keksobot
Copy link
Contributor

♻️ Я собрал ваш пулреквест. Посмотреть можно здесь.

js/functions.js Outdated
const isLessOrEqual = (testString, amountSymbols) =>{
if (testString.length <= amountSymbols){
return true;
}else {

Choose a reason for hiding this comment

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

Не используем условия если результат ожидается boolen - возвращаем логическое выражение

return testString.length <= amountSymbols;

js/functions.js Outdated

const isPalindrom = (text) =>{
const unspacedText = text.replaceAll(' ', '');
const normalizedText = unspacedText.toUpperCase();

Choose a reason for hiding this comment

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

Полезно применить цепочку, так как нет необходимости в промежуточной константе

const normalizedText = text.replaceAll(' ', '').toUpperCase();

js/functions.js Outdated
const unspacedText = text.replaceAll(' ', '');
const normalizedText = unspacedText.toUpperCase();
let reversedText = '';
for (let lastIndex = normalizedText.length - 1; lastIndex >= 0 ; lastIndex --) {

Choose a reason for hiding this comment

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

  1. команды явного присвоения более удобные для чтения

длинная запись

lastIndex = lastIndex - 1

короткая, которая принята в общей практике

lastIndex -= 1
  1. название индекса
    Название lastIndeex сложно ассоциировать с реальным назначением. Фактически, это просто "индекс" - индексы в циклах принято называть односимвольными названиями, по порядку вложенности циклов: i, j, n, m

Т.е., если цикл основной или единственный - индекс всегда именуется i

js/functions.js Outdated
for (let lastIndex = normalizedText.length - 1; lastIndex >= 0 ; lastIndex --) {
reversedText += normalizedText.at(lastIndex);
}
if(normalizedText === reversedText){

Choose a reason for hiding this comment

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

Вернуть можно результат логического выражения - условие не требуется

@keksobot
Copy link
Contributor

♻️ Я собрал ваш пулреквест. Посмотреть можно здесь.

keksobot pushed a commit that referenced this pull request May 28, 2025
@keksobot keksobot merged commit 774ac85 into htmlacademy-javascript:master May 29, 2025
1 check failed
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