-
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
2 changed files
with
47 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function checkLengthString(string = '', length = 1) { | ||
return (string <= length); | ||
} | ||
console.log(checkStringLength('тестовая строка', 5)); | ||
Check failure on line 4 in js/functions.js GitHub Actions / Check
|
||
|
||
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) { | ||
Check failure on line 27 in js/functions.js GitHub Actions / Check
|
||
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)); |