Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Нужно больше функций #2

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="/js/functions.js"></script>
<title>Кекстаграм</title>
</head>

Expand Down
53 changes: 53 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

function checkLengthString(string = '', length = 1) {
return (string <= length);
}

console.log(checkLengthString('тестовая строка', 5));

Check failure on line 6 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement


function findPolydrome(string = '') {
string = string.replaceAll(' ', '').toLowerCase();

let reversedLength = '';

for (let i = string.length - 1; i >= 0; i--) {
reversedLength += string[1];
}
return string === reversedLength;
}

console.log('\n--- Тесты для findPolydrome ---');

Check failure on line 20 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(`Строка является палиндромом: ${findPolydrome('топот') === true}`);

Check failure on line 21 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(`Строка является палиндромом с разным регистром: ${findPolydrome('ДовОд') === true}`);

Check failure on line 22 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(`Строка не является палиндромом: ${findPolydrome('Кекс') === false}`);

Check failure on line 23 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(`Строка является палиндромом: ${findPolydrome('Лёша на полке клопа нашёл ') === true}`);

Check failure on line 24 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement

// Функция принимает строку,
// извлекает содержащиеся в ней цифры от 0 до 9 и возвращает их в виде целого положительного числа. Если в строке нет ни одной цифры, функция должна вернуть NaN:

function extractsNumbers(string = '') {

let result = '';
string = string.toString();

for (let i = 0; i <= string.length - 1; i++) {
if (parseInt(string[i], 10) || parseInt(string[i], 10) === 0) {
result += string[i];
}
}

if (result) {
return Number(result);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else в конце функций не нужен. Можно просто сделать return

return NaN;
}

}

console.log(extractsNumbers('2023 год'));

Check failure on line 48 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(extractsNumbers('ECMAScript 2022'));

Check failure on line 49 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(extractsNumbers('1 кефир, 0.5 батона'));

Check failure on line 50 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(extractsNumbers('агент 007'));

Check failure on line 51 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(extractsNumbers('а я томат'));
console.log(extractsNumbers(-1));
Loading