Skip to content

Commit

Permalink
Merge pull request #3 from nikitakhrulev/module2-task1
Browse files Browse the repository at this point in the history
Нужно больше функций
  • Loading branch information
craz3r authored Nov 15, 2024
2 parents c8f2202 + be62b06 commit 0b8aabc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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>
42 changes: 42 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1
const checkLength = (str, length) => str.length <= length;
checkLength('проверяемая строка', 20); // true
checkLength('проверяемая строка', 18); // true
checkLength('проверяемая строка', 10); // false

// 2
const isPalindrome = (str) => {
str = str.replace(/ /g, '').toLowerCase();
let a = 0;
let b = str.length - 1;
while (a <= b) {
if (str[a] === str[b]) {
a++;
b--;
} else {
return false;
}
}
return true;
};

isPalindrome('топот'); // true
isPalindrome('ДовОд'); // true
isPalindrome('Кекс'); // false
isPalindrome('Лёша на полке клопа нашёл'); // true

// 3
const getNumbers = (input) => {
const str = input.toString();
const numbers = str.match(/\d/g);
return numbers ? parseInt(numbers.join(''), 10) : NaN;
};

getNumbers('2023 год'); // 2023
getNumbers('ECMAScript 2022'); // 2022
getNumbers('1 кефир, 0.5 батона'); // 105
getNumbers('агент 007'); // 7
getNumbers('а я томат'); // NaN
getNumbers(2023); // 2023
getNumbers(-1); // 1
getNumbers(1.5); // 15
Empty file removed js/main.js
Empty file.

0 comments on commit 0b8aabc

Please sign in to comment.