From 7f84cdcf9b2beab77f2ffcb72019af1404719c91 Mon Sep 17 00:00:00 2001 From: ClaireFotina Date: Thu, 17 Oct 2024 21:22:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=B5=D1=82=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/functions.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 js/functions.js diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..44dc821 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,39 @@ +//task 1 + +const checkLength = (text, maxLength) => text.length <= maxLength; + +//console.log(checkLength('gjglh', 10)) + + +// task 2 + +const checkPalindrome = (text) => { + const currentText = text.replaceAll(' ', '').toLowerCase(); + let palindrome = ''; + + for (let i = currentText.length - 1; i >= 0; i--) { + palindrome = palindrome + currentText.at(i); + } + + return palindrome === currentText; +} + +//console.log(checkPalindrome('Шалаш')) + +//task 3 + +const cutNumber = (text) => { + const currentText = String(text); + let number = ''; + for (let i = 0; i < currentText.length; i++) { + if (!Number.isNaN(parseInt(currentText.at(i), 10))) { + number = number + currentText.at(i); + } + } + + return parseInt(number, 10); +} + +//console.log(cutNumber('dhjlh4 hlfgh3 f7 j e8')) + +// 4378 \ No newline at end of file