From ed0a6fefaec890680e9b82eaf5221e76c1d06cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A8=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Fri, 29 Nov 2024 21:55:22 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 1 + js/functions.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 js/functions.js diff --git a/index.html b/index.html index 9fb6740..e02b4b9 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@ + Кекстаграм diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..cbdf3f8 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,46 @@ +function checkLengthString(string = '', length = 1) { + return (string <= length); +} +console.log(checkStringLength('тестовая строка', 5)); + +function findPolydrome(string = '') { + string = string.replaceAll(' ', '').toLowerCase(); + + let reversedLength = ''; + + for (let i = string.length - 1; i >= 0; i--) { + reversedLength += string[1]; + } + + return string === reversedLength; +} + +// Функция принимает строку, +// извлекает содержащиеся в ней цифры от 0 до 9 и возвращает их в виде целого положительного числа. Если в строке нет ни одной цифры, функция должна вернуть NaN: + +function extractsNumbers(string = '') { + + let str = ''; + let newStr = string.toString(); + + for (let i = 0; i <= newStr.length - 1; i++) { + if (parseInt(newStr[i]) || parseInt(newStr[i]) === 0) { + str += newStr[i]; + } + } + + if (str) { + let num = Number(str); + return Math.abs(num); + } else { + return NaN; + } + +} + +console.log(extractsNumbers('2023 год')); +console.log(extractsNumbers('ECMAScript 2022')); +console.log(extractsNumbers('1 кефир, 0.5 батона')); +console.log(extractsNumbers('агент 007')); +console.log(extractsNumbers('а я томат')); +console.log(extractsNumbers(-1)); From ea7655ec4193f1ed1df0f0a6f5d6395f22ad32f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A8=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Fri, 29 Nov 2024 22:24:23 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/functions.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/functions.js b/js/functions.js index cbdf3f8..5694690 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,8 +1,9 @@ +// eslint-disable-next-line no-unused-vars function checkLengthString(string = '', length = 1) { return (string <= length); } -console.log(checkStringLength('тестовая строка', 5)); +// eslint-disable-next-line no-unused-vars function findPolydrome(string = '') { string = string.replaceAll(' ', '').toLowerCase(); @@ -11,7 +12,6 @@ function findPolydrome(string = '') { for (let i = string.length - 1; i >= 0; i--) { reversedLength += string[1]; } - return string === reversedLength; } @@ -21,16 +21,16 @@ function findPolydrome(string = '') { function extractsNumbers(string = '') { let str = ''; - let newStr = string.toString(); + const newStr = string.toString(); for (let i = 0; i <= newStr.length - 1; i++) { - if (parseInt(newStr[i]) || parseInt(newStr[i]) === 0) { + if (parseInt(newStr[i], 10) || parseInt(newStr[i], 10) === 0) { str += newStr[i]; } } if (str) { - let num = Number(str); + const num = Number(str); return Math.abs(num); } else { return NaN; @@ -38,9 +38,15 @@ function extractsNumbers(string = '') { } +// eslint-disable-next-line no-console console.log(extractsNumbers('2023 год')); +// eslint-disable-next-line no-console console.log(extractsNumbers('ECMAScript 2022')); +// eslint-disable-next-line no-console console.log(extractsNumbers('1 кефир, 0.5 батона')); +// eslint-disable-next-line no-console console.log(extractsNumbers('агент 007')); +// eslint-disable-next-line no-console console.log(extractsNumbers('а я томат')); +// eslint-disable-next-line no-console console.log(extractsNumbers(-1)); From e433416b7632eefcda75f158c762c333a51b4b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A8=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Tue, 3 Dec 2024 23:19:31 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=8E=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/functions.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/js/functions.js b/js/functions.js index 5694690..01c6f89 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,9 +1,11 @@ -// eslint-disable-next-line no-unused-vars + function checkLengthString(string = '', length = 1) { return (string <= length); } -// eslint-disable-next-line no-unused-vars +console.log(checkLengthString('тестовая строка', 5)); + + function findPolydrome(string = '') { string = string.replaceAll(' ', '').toLowerCase(); @@ -15,38 +17,37 @@ function findPolydrome(string = '') { return string === reversedLength; } +console.log('\n--- Тесты для findPolydrome ---'); +console.log(`Строка является палиндромом: ${findPolydrome('топот') === true}`); +console.log(`Строка является палиндромом с разным регистром: ${findPolydrome('ДовОд') === true}`); +console.log(`Строка не является палиндромом: ${findPolydrome('Кекс') === false}`); +console.log(`Строка является палиндромом: ${findPolydrome('Лёша на полке клопа нашёл ') === true}`); + // Функция принимает строку, // извлекает содержащиеся в ней цифры от 0 до 9 и возвращает их в виде целого положительного числа. Если в строке нет ни одной цифры, функция должна вернуть NaN: function extractsNumbers(string = '') { - let str = ''; - const newStr = string.toString(); + let result = ''; + string = string.toString(); - for (let i = 0; i <= newStr.length - 1; i++) { - if (parseInt(newStr[i], 10) || parseInt(newStr[i], 10) === 0) { - str += newStr[i]; + for (let i = 0; i <= string.length - 1; i++) { + if (parseInt(string[i], 10) || parseInt(string[i], 10) === 0) { + result += string[i]; } } - if (str) { - const num = Number(str); - return Math.abs(num); + if (result) { + return Number(result); } else { return NaN; } } -// eslint-disable-next-line no-console console.log(extractsNumbers('2023 год')); -// eslint-disable-next-line no-console console.log(extractsNumbers('ECMAScript 2022')); -// eslint-disable-next-line no-console console.log(extractsNumbers('1 кефир, 0.5 батона')); -// eslint-disable-next-line no-console console.log(extractsNumbers('агент 007')); -// eslint-disable-next-line no-console console.log(extractsNumbers('а я томат')); -// eslint-disable-next-line no-console console.log(extractsNumbers(-1));