From cc0409b2b671159e38c6dde08b73e6e9e45657bb Mon Sep 17 00:00:00 2001 From: Elisanov Nikolay Date: Fri, 22 Nov 2024 19:16:27 +0300 Subject: [PATCH] added function.js --- js/function.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 js/function.js diff --git a/js/function.js b/js/function.js new file mode 100644 index 0000000..0c87155 --- /dev/null +++ b/js/function.js @@ -0,0 +1,31 @@ +const checkStringLength = (string, length) => string.length <= length; + +checkStringLength('проверяемая строка', 10); + + +function validatePalindrome(string) { + string = string.replaceAll(' ', '').toLowerCase(); + let result = ''; + for(let i = string.length - 1; i >= 0; i--) { + result += string[i]; + } + return string === result; +} + +validatePalindrome('Лёша на полке клопа нашёл'); + + +function getNumberFromString(string) { + string = string.toString().replaceAll(' ', ''); + let result = ''; + for(let i = 0; i < string.length; i++) { + if(Number.isNaN(parseInt(string[i], 10))){ + continue; + } + result += string[i]; + } + + return parseInt(result, 10); +} + +getNumberFromString('ECMAScript 2022');