-
Notifications
You must be signed in to change notification settings - Fork 1
Нужно больше функций #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| function checkStringLength(str, maxLength) { | ||
| return str.length <= maxLength; | ||
| } | ||
|
|
||
| function isPalindrome(str) { | ||
| const normalizedStr = str.replaceAll(' ', '').toLowerCase(); | ||
| let reversedStr = ''; | ||
| for (let i = normalizedStr.length - 1; i >= 0; i--) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for - хорошо, но давай подумаем про методы массива, какие тут могли бы нам пригодиться для решения задачки |
||
| reversedStr += normalizedStr[i]; | ||
| } | ||
| return normalizedStr === reversedStr; | ||
| } | ||
|
|
||
| function extractNumber(str) { | ||
| const string = str.toString(); | ||
| let result = ''; | ||
| for (let i =0; i < string.length; i++) { | ||
| 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)); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| "devDependencies": { | ||
| "eslint": "8.48.0", | ||
| "eslint-config-htmlacademy": "9.1.1", | ||
| "vite": "4.4.9" | ||
| "vite": "^4.4.9" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. очень рекомендую не фиксировать версии или тут необходимо было по заданию, но врятли |
||
| }, | ||
| "license": "MIT", | ||
| "scripts": { | ||
|
|
||
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.
давай использовать как можно чаще "стрелочные функции"
эту функцию нам стрелочная позволит написать в одну строку, напиши потом исправление в чатик