Skip to content
Open
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
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

#ENV
env/
.env

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
34 changes: 34 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test_dataTypes</title>
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
</head>

<body>
<div id="mocha"></div>
<div id="messages"></div>
<div id="fixtures"></div>
<script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Faker/2.2.2/faker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/8.0.1/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/1.4.1/chai.js"></script>
<script src="src/operators.js"></script>
<script src="src/cycle.js"></script>
<script src="src/functions.js"></script>
<script src="src/array.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test/operators.spec.js"></script>
<script src="test/cycle.spec.js"></script>
<script src="test/functions.spec.js"></script>
<script src="test/array.spec.js"></script>
<script>
mocha.run();
</script>
</body>

</html>
108 changes: 61 additions & 47 deletions src/array.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,88 @@
// 1. Найти минимальный элемент массива
let minNum = [5, 2, 40, 27, 17, 3];
let min = minNum[0];
function minNum(minArray) {
let min = minArray[0];

for (let i = 1; i < minNum.length; i++) {
if (min > minNum[i]) {
min = minNum[i];
}
for (let i = 1; i < minArray.length; i++) {
if (min > minArray[i]) {
min = minArray[i];
}

}
return min;
}
console.log(min);
console.log(minNum([5, 2, 40, 27, 17, 3]))

// 2. Найти максимальный элемент массива
let maxNum = [5, 2, 40, 27, 17, 3];
let max = maxNum[0];
function maxNum(maxArray) {
let max = maxArray[0];

for (let i = 1; i < maxNum.length; i++) {
if (max < maxNum[i]) {
max = maxNum[i];
}
for (let i = 1; i < maxArray.length; i++) {
if (max < maxArray[i]) {
max = maxArray[i];
}

}
return max;
}
console.log(max);
console.log(maxNum([5, 2, 40, 27, 17, 3]));

// 3. Найти индекс минимального элемента массива
let minInd = [5, 2, 40, 27, 17, 3];
let minN = minInd[0];
let minIndex;
function minimumIndex(array) {
let minN = array[0];
let minIndex;
for (let i = 1; i < array.length; i++) {

for (let i = 1; i < minInd.length; i++) {
if (minN > minInd[i]) {
minN = minInd[i];
minIndex = i;
}
if (minN > array[i]) {
minN = array[i];
minIndex = i;
}

}
return minIndex;
}
console.log(minIndex);
console.log(minimumIndex([5, 7, 40, 2, 17, 3]))

// 4. Найти индекс максимального элемента массива
let maxInd = [5, 2, 40, 27, 17, 3];
let maxN = maxInd[0];
let maxIndex;
function maximumIndex(array) {
let maxN = array[0];
let maxIndex;

for (let i = 1; i < maxInd.length; i++) {
if (maxN < maxInd[i]) {
maxN = maxInd[i];
maxIndex = i;
}
for (let i = 1; i < array.length; i++) {
if (maxN < array[i]) {
maxN = array[i];
maxIndex = i;
}

}
return maxIndex;
}
console.log(maxIndex);
console.log(maximumIndex([5, 2, 40, 27, 17, 3]))

// 5. Посчитать сумму элементов массива с нечетными индексами
let oddArray = [3, 6, 24, 78, 36, 49, 7, 11, 1];
let oddSum = 0;
for (let i = 1; i < oddArray.length; i = i + 2) {
oddSum = oddSum + oddArray[i];
function oddArray(array) {
let oddSum = 0;
for (let i = 1; i < array.length; i = i + 2) {
oddSum = oddSum + array[i];
}
return oddSum;
}
console.log(oddSum);
console.log(oddArray([3, 6, 24, 78, 36, 49, 7, 11, 1]))

// 6. Сделать реверс массива (массив в обратном направлении)
let revArray = [1, 2, 3, 4, 5];
revArray.reverse();
console.log(revArray);
// 6. Сделать реверс массива (массив в обратном направлении)[1, 2, 3, 4, 5];
function revArray(array) {
array.reverse();
return (array);
}
console.log(revArray([1, 2, 3, 4, 5]))

// 7. Посчитать количество нечетных элементов массива
let oddElArray = [2, 3, 5, 7, 4, 6, 1];
let counter = 0;
for (let i = 0; i < oddElArray.length; i++) {
if (oddElArray[i] % 2 != 0) {
counter++;
function oddElArray(array) {
let counter = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] % 2 != 0) {
counter++;
}
}
return counter;
}
console.log(counter);
console.log(oddElArray([2, 3, 5, 7, 4, 6, 1]))
93 changes: 53 additions & 40 deletions src/cycle.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,75 @@
// 1. Найти сумму четных чисел и их количество в диапазоне от 1 до 99
let res = 0;
for (let i = 0; i < 99; i = i + 2) {
res = res + i;
function sumEven(res) {
for (let i = 0; i < 99; i = i + 2) {
res = res + i;
}
return res
}
console.log(res);
console.log(sumEven(0))

/* 2. Проверить простое ли число? (число называется простым, если оно делится только
само на себя и на 1)*/
let num = 5;
let flag = true;
for (let i = 2; i < num; i++) {
if (num % i == 0) {
flag = false;
break;
function checkNum(num) {
let flag = true;
for (let i = 2; i < num; i++) {
if (num % i == 0) {
flag = false;
break;
}
}
return flag;
}

console.log(flag);
console.log(checkNum(5))

/* 3. Найти корень натурального числа с точностью до целого (рассмотреть вариант
последовательного подбора и метод бинарного поиска)*/
let n = 9, r;
for (let i = 1; i < n; i++) {
if (i * i === n) {
r = i;
break;
}
function rootNum(num) {
let r;
for (let i = 1; i < num; i++) {
if (i * i === num) {
r = i;
break;
}

}
if (r === undefined) {
return ('Целого корня нет!');
}
else return (r);
}
if (r === undefined) {
console.log('Целого корня нет!');
}
else console.log(r);
console.log(rootNum(5))

// 4. Вычислить факториал числа n. n! = 1*2*…*n-1*n;
let f = 3, fact = 1;
for (let i = 1; i <= f; i++) {
fact = fact * i;
function factNum(f, fact) {
for (let i = 1; i <= f; i++) {
fact = fact * i;
}
return fact;
}
console.log(fact);
console.log(factNum(5, 1))

// 5. Посчитать сумму цифр заданного числа
let a = 352, sum = 0, tmp;
while (a > 0) {
tmp = a % 10;
sum = sum + tmp;
a = (a - tmp) / 10;
function sumNum(a) {
let sum = 0, tmp;
while (a > 0) {
tmp = a % 10;
sum = sum + tmp;
a = (a - tmp) / 10;
}
return (sum);
}
console.log(sum);
console.log(sumNum(352))

/* 6. Вывести число, которое является зеркальным отображением последовательности
цифр заданного числа, например, задано число 123, вывести 321.*/
let b = 1234, reverse = 0, temp, i = 1000;
while (b) {
temp = b % 10;
reverse += temp * i;
i = i / 10;
b = (b - temp) / 10;
function reversNum(b) {
let reverse = 0, temp, i = 1000;
while (b) {
temp = b % 10;
reverse += temp * i;
i = i / 10;
b = (b - temp) / 10;
}
return reverse
}

console.log(reverse);
console.log(reversNum(1234))
7 changes: 2 additions & 5 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ let n = d.getDay();
console.log(days[n]);

// 2 Задание
let a = 3, b = 5;

console.log(sumA(a, b))

function sumA(x, y) {
return x + y;
}
}
console.log(sumA(3, 5))
Loading