Skip to content

Commit

Permalink
module2Task1
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfxllen committed Nov 20, 2024
1 parent ed1cf58 commit bec6737
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,5 @@ <h2 class="success__title">Изображение успешно загруже
</template>

</body>
<script src="js/function.js"></script>
</html>
52 changes: 52 additions & 0 deletions js/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function checkMaxLength(string, maxLength){
return string.length <= maxLength;

Check failure on line 2 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
}
// Cтрока короче 20 символов
checkMaxLength('проверяемая строка', 20); // true
// Длина строки ровно 18 символов
checkMaxLength('проверяемая строка', 18); // true
// Строка длиннее 10 символов
checkMaxLength('проверяемая строка', 10); // false


function isPalindrome(word){
if (!word.length){

Check failure on line 13 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
return ;

Check failure on line 14 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 4 spaces but found 8
}

Check failure on line 15 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
word = word.toLowerCase()

Check failure on line 16 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4

Check failure on line 16 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
word = word.replaceAll(' ', '')

Check failure on line 17 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4

Check failure on line 17 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
let lastLetter = word.length - 1;

Check failure on line 18 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

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

Check failure on line 19 in js/function.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
if (word[i] != word[lastLetter]){
return false;
} else{
lastLetter -= 1;
}
}
return true;
}

// Строка является палиндромом
isPalindrome('топот'); // true
// Несмотря на разный регистр, тоже палиндром
isPalindrome('ДовОд'); // true
// Это не палиндром
isPalindrome('Кекс'); // false
isPalindrome('Лёша на полке клопа нашёл ');

function takeNum(string){
let result = '';
let numbers = '0123456789';
for (let i = 0; i < string.length; i++){
if (numbers.includes(string[i])){
result += string[i]
}
}
return parseInt(result);
}

takeNum('2023 год'); // 2023
takeNum('ECMAScript 2022'); // 2022
takeNum('1 кефир, 0.5 батона'); // 105
takeNum('агент 007'); // 7
takeNum('а я томат'); // Nan

0 comments on commit bec6737

Please sign in to comment.