Skip to content
Open

DZ #2

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
9 changes: 9 additions & 0 deletions 11-date-array/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const date = ['10-02-2022', 'тест', '11/12/2023', '00/12/2022', '41/12/2023', '30/02/2024'];

const validDates = date
.map(date => new Date(date))
.filter(date => !isNaN(date))
.map(date => date.toLocaleDateString('ru-RU'))
.sort((a, b) => a - b);

console.log(validDates);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Результат работы этой функции - мутация над исходными данными - ['02.10.2022', '12.11.2023']
В исходном массиве формат даты задан по другому))

12 changes: 12 additions & 0 deletions 11-date-array/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>
27 changes: 27 additions & 0 deletions 12-luna/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const card = '4561-2612-1234-5464';

function correctCardNumber (cardNum) {
console.log(cardNum);
cardNum = cardNum
.trim()
.replaceAll('-', '')
console.log(cardNum)

if (cardNum.length != 16) {
return false;
}
// Проверка по Алгоритму Луны
let sum = 0;
for (let i = 0; i < cardNum.length; i++) {
let numbers = Number(cardNum[i]);
if ((cardNum.length - i) % 2 === 0) {
numbers *= 2;
if (numbers >= 9) {
numbers -= 9;
}
sum += numbers;
}
}
return sum % 10 === 0;
}
console.log(correctCardNumber(card));
12 changes: 12 additions & 0 deletions 12-luna/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./app.js"></script>
<title>Document</title>
</head>
<body>

</body>
</html>
32 changes: 32 additions & 0 deletions 7-converter/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function summ (amount, sourceCurrency, targetCurrency) {
switch (sourceCurrency) {
case 'RUB': switch (targetCurrency) {
case 'USD': return amount / 89.7619;
case 'EUR': return amount / 97.9126;
case 'GBP': return amount / 113.6027;
default: return null;
}
case 'USD': switch (targetCurrency) {
case 'RUB': return amount * 89.7619;
case 'EUR': return amount * 0.9168;
case 'GBP': return amount * 0.7901;
default: return null;
}
case 'EUR': switch (targetCurrency) {
case 'RUB': return amount * 97.9126;
case 'USD': return amount * 1.0908;
case 'GBP': return amount * 0.8619;
default: return null;
}
case 'GBP': switch (targetCurrency) {
case 'RUB': return amount * 113.6027;
case 'USD': return amount * 1.2656;
case 'EUR': return amount * 1.1602;
default: return null;
}
default:
return null;
}
};

console.log(summ(1000, 'RUB', 'USD'));
12 changes: 12 additions & 0 deletions 7-converter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>
22 changes: 22 additions & 0 deletions 8-crypto/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function crypto(password) {
let cryptoPass = password.split(['']);
cryptoPass.reverse();
return cryptoPass;
};
console.log(crypto('password'));


function check() {
let encryptedPass = crypto('password');
encryptedPass.reverse();
let truePass = encryptedPass.join('');

switch (truePass) {
case 'password':
console.log('Пароль верный!');
break;
default:
console.log('Пароль неверный!');
};
};
console.log(check());
12 changes: 12 additions & 0 deletions 8-crypto/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>
15 changes: 15 additions & 0 deletions 9-sort-loops/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const arr = [1, 40, -50, -20, -10, 5, 0, 100];

function arrSort() {
for (let j = arr.length - 1; j > 0; j--) {
for (let i = 0; i < j; i++) {
if (arr[i] > arr[i + 1]) {
let temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
};
};
};
return arr;
}
console.log(arrSort(arr));
12 changes: 12 additions & 0 deletions 9-sort-loops/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./app.js"></script>
</head>
<body>

</body>
</html>