Skip to content
Merged
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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>

<script src="js/functions.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function checkStringLength(str, maxLength) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

давай использовать как можно чаще "стрелочные функции"

эту функцию нам стрелочная позволит написать в одну строку, напиши потом исправление в чатик

return str.length <= maxLength;

Check failure on line 2 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
}

function isPalindrome(str) {
const normalizedStr = str.replaceAll(' ', '').toLowerCase();

Check failure on line 6 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
let reversedStr = '';

Check failure on line 7 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
for (let i = normalizedStr.length - 1; i >= 0; i--) {

Check failure on line 8 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

for - хорошо, но давай подумаем про методы массива, какие тут могли бы нам пригодиться для решения задачки

reversedStr += normalizedStr[i];

Check failure on line 9 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 4 spaces but found 8
}

Check failure on line 10 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
return normalizedStr === reversedStr;

Check failure on line 11 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
}

function extractNumber(str) {
const string = str.toString();

Check failure on line 15 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
let result = '';

Check failure on line 16 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
for (let i =0; i < string.length; i++) {

Check failure on line 17 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
const char = string[i];
const digit = parseInt(char, 10);
if (!Number.isNaN(digit)) {
result += char;
}
}
if (result === '') {
return NaN;
}
return parseInt(result, 10);
}

console.log(checkStringLength('проверяемая строка', 20));
console.log(checkStringLength('проверяемая строка', 18));
console.log(checkStringLength('проверяемая строка', 10));

console.log(isPalindrome('топот'));
console.log(isPalindrome('ДовОд'));
console.log(isPalindrome('Кекс'));
console.log(isPalindrome('Лёша на полке клопа нашёл '));

console.log(extractNumber('2023 год'));
console.log(extractNumber('ECMAScript 2022'));
console.log(extractNumber('1 кефир, 0.5 батона'));
console.log(extractNumber('агент 007'));
console.log(extractNumber('а я томат'));

console.log(extractNumber(2023));
console.log(extractNumber(-1));
console.log(extractNumber(1.5));
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"eslint": "8.48.0",
"eslint-config-htmlacademy": "9.1.1",
"vite": "4.4.9"
"vite": "^4.4.9"
Copy link
Collaborator

Choose a reason for hiding this comment

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

очень рекомендую не фиксировать версии

или тут необходимо было по заданию, но врятли

},
"license": "MIT",
"scripts": {
Expand Down