-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
function checkMaxLength(string, maxLength){ | ||
return string.length <= maxLength; | ||
function checkMaxLength(string, maxLength) { | ||
return string.length <= maxLength; | ||
} | ||
// Cтрока короче 20 символов | ||
checkMaxLength('проверяемая строка', 20); // true | ||
checkMaxLength("проверяемая строка", 20); // true | ||
// Длина строки ровно 18 символов | ||
checkMaxLength('проверяемая строка', 18); // true | ||
checkMaxLength("проверяемая строка", 18); // true | ||
// Строка длиннее 10 символов | ||
checkMaxLength('проверяемая строка', 10); // false | ||
checkMaxLength("проверяемая строка", 10); // false | ||
|
||
|
||
function isPalindrome(word){ | ||
if (!word.length){ | ||
return ; | ||
} | ||
word = word.toLowerCase() | ||
word = word.replaceAll(' ', '') | ||
let lastLetter = word.length - 1; | ||
for (let i = 0; i <= Math.round(word.length / 2); i++){ | ||
if (word[i] != word[lastLetter]){ | ||
return false; | ||
} else{ | ||
lastLetter -= 1; | ||
} | ||
function isPalindrome(word) { | ||
if (!word.length) { | ||
return; | ||
} | ||
word = word.toLowerCase(); | ||
word = word.replaceAll(" ", ""); | ||
Check failure on line 16 in js/function.js GitHub Actions / Check
|
||
let lastLetter = word.length - 1; | ||
for (let i = 0; i <= Math.round(word.length / 2); i++) { | ||
if (word[i] != word[lastLetter]) { | ||
return false; | ||
} else { | ||
lastLetter -= 1; | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
|
||
// Строка является палиндромом | ||
isPalindrome('топот'); // true | ||
isPalindrome("топот"); // true | ||
// Несмотря на разный регистр, тоже палиндром | ||
isPalindrome('ДовОд'); // true | ||
isPalindrome("ДовОд"); // true | ||
// Это не палиндром | ||
isPalindrome('Кекс'); // false | ||
isPalindrome('Лёша на полке клопа нашёл '); | ||
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] | ||
} | ||
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); | ||
} | ||
return parseInt(result); | ||
} | ||
|
||
takeNum('2023 год'); // 2023 | ||
takeNum('ECMAScript 2022'); // 2022 | ||
takeNum('1 кефир, 0.5 батона'); // 105 | ||
takeNum('агент 007'); // 7 | ||
takeNum('а я томат'); // Nan | ||
takeNum("2023 год"); // 2023 | ||
takeNum("ECMAScript 2022"); // 2022 | ||
takeNum("1 кефир, 0.5 батона"); // 105 | ||
takeNum("агент 007"); // 7 | ||
takeNum("а я томат"); // Nan |