From 45a7368eac6b221bbe7f0462d4a496b4ba53ccc6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-QOPDFPB\\ARTEMIY" Date: Sat, 23 Oct 2021 10:22:31 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=90.=D0=9C.=20=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topic-2/task-1/index.js | 25 +++++++++++++++++++++++-- topic-2/task-2/index.js | 22 +++++++++++++++++++--- topic-2/task-3/index.js | 33 +++++++++++++++++++++++++++++++-- topic-2/task-4/index.js | 10 +++++++--- topic-2/task-5/index.js | 8 +++++--- topic-2/task-6/index.js | 19 +++++++++++++++++-- 6 files changed, 102 insertions(+), 15 deletions(-) diff --git a/topic-2/task-1/index.js b/topic-2/task-1/index.js index 4739c57..585065d 100644 --- a/topic-2/task-1/index.js +++ b/topic-2/task-1/index.js @@ -9,9 +9,30 @@ * @returns массив с удаленным элементом */ function removeSmallest(numbers) { - + if (Array.isArray(numbers)) { + arr = numbers //Исходя из условий задачи, что исходный массив нельзя изменять + if (arr.every(elem => typeof elem === 'number')) { + let a = +Infinity + for (i = 0; i < arr.length; i++) { + if (a > arr[i]) { + a = arr[i] + } + } + let index = arr.indexOf(a) + arr.splice(index, 1) + return arr + } + else if (arr === []) { + return arr + } + else { + throw new Error('Ожидался массив чисел, либо пустой массив') + } + } + else { + throw new Error('Ожидался массив') + } } - module.exports.removeSmallest = removeSmallest; diff --git a/topic-2/task-2/index.js b/topic-2/task-2/index.js index d1e3e9a..a5b6b29 100644 --- a/topic-2/task-2/index.js +++ b/topic-2/task-2/index.js @@ -14,8 +14,24 @@ * @returns массив разбитый на группы */ const arrayStripped = (array, size) => { - + if (Number.isInteger(size) && Array.isArray(array)) { + const a = array.length / size + let arr = [] + for (i = 0; i < a; i++) { + let arr_1 = [] + for (b = 0; b < size; b++) { + if (array.length === 0) { + break + } + arr_1.push(array[0]) + array.splice(0, 1) + } + arr.push(arr_1) + } + return arr + } + else { + throw new Error('Ожидался массив и целосчисленный разделитель') + } } - - module.exports.arrayStripped = arrayStripped; diff --git a/topic-2/task-3/index.js b/topic-2/task-3/index.js index 66dddf4..fbca53b 100644 --- a/topic-2/task-3/index.js +++ b/topic-2/task-3/index.js @@ -16,7 +16,36 @@ * @param {*} group */ function isGroup(group) { - + if (typeof group === 'string') { + if (group == '') { + return true + } + let arr = group.split('') + let a = arr.toString() + let b = arr.length + let d = Array.from(new Set(arr)).toString() + if (arr.every(elem => elem === '(' || ')' || '[' || ']' || '{' || '}') && b % 2 == 0 && d === a && arr[0] != ')' && arr[0] != ']' && arr[0] != '}') { + for (i = 0; i < b; i++) { + if (group[i] === '(') { + if (group[b - 1 - i] !== ')' && group[i + 1] !== ')') { + return false + } + } + else if (group[i] === '[') { + if (group[b - 1 - i] !== ']' && group[i + 1] !== ']') { + return false + } + } + else if (group[i] === '{') { + if (group[b - 1 - i] !== '}' && group[i + 1] !== '}') { + return false + } + } + } + return true + } + else return false + } + else throw new Error('Ожидалась строка') } - module.exports.isGroup = isGroup; \ No newline at end of file diff --git a/topic-2/task-4/index.js b/topic-2/task-4/index.js index c6e9209..7517a86 100644 --- a/topic-2/task-4/index.js +++ b/topic-2/task-4/index.js @@ -7,10 +7,14 @@ const miniMathLib = { pi: 3.14, - circleArea: function(radius) { - + circleArea: function (radius) { + if (typeof radius === 'number'&&radius>0) { + return Math.pow(radius, 2) * this.pi + } + else{ + throw new Error('Радиус должен быть положительным числом') + } } } - module.exports.miniMathLib = miniMathLib \ No newline at end of file diff --git a/topic-2/task-5/index.js b/topic-2/task-5/index.js index 7dbbaf3..2a198c0 100644 --- a/topic-2/task-5/index.js +++ b/topic-2/task-5/index.js @@ -1,4 +1,4 @@ -import {miniMathLib} from "../task-4"; +import { miniMathLib } from "../task-4"; /** * Задача 5 - Нехватка точности @@ -7,8 +7,10 @@ import {miniMathLib} from "../task-4"; * Модифицировать miniMathLib из прошлой задачи - запрещено */ function accurateAreaCalc() { - + return function (radius) { + return (3.14159 * miniMathLib.circleArea(radius)) / miniMathLib.pi + } } - +accurateAreaCalc() module.exports.accurateAreaCalc = accurateAreaCalc \ No newline at end of file diff --git a/topic-2/task-6/index.js b/topic-2/task-6/index.js index 19898e1..3396f2c 100644 --- a/topic-2/task-6/index.js +++ b/topic-2/task-6/index.js @@ -10,10 +10,25 @@ * в которую передается значение Пи, необходимое для расчетов * */ const miniMathLibExtended = { + pi: 3.14, + volume(radius, height) { + if (typeof (radius && height) === 'number' && (radius && height) > 0) { + return Math.pow(radius, 2) * this.pi * height + } + else { + throw new Error('Радиус и высота должны быть положительным числом') + } + } } -function cylinderVolumeAccurate(pi){ - +function cylinderVolumeAccurate(pi) { + if (typeof pi === 'number' && pi > 0) { + return function (radius, height) { + return miniMathLibExtended.volume(radius, height) / miniMathLibExtended.pi * pi + } + } else { + throw new Error('Число Пи должно быть положительным') + } } module.exports.miniMathLibExtended = miniMathLibExtended; From 8754813268707050678d7c757abc7512a56a3bbd Mon Sep 17 00:00:00 2001 From: "DESKTOP-QOPDFPB\\ARTEMIY" Date: Sat, 23 Oct 2021 10:37:27 +0500 Subject: [PATCH 2/5] up --- topic-2/task-6/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/topic-2/task-6/index.js b/topic-2/task-6/index.js index 3396f2c..19d41f7 100644 --- a/topic-2/task-6/index.js +++ b/topic-2/task-6/index.js @@ -12,7 +12,7 @@ const miniMathLibExtended = { pi: 3.14, volume(radius, height) { - if (typeof (radius && height) === 'number' && (radius && height) > 0) { + if (typeof (radius && height) === 'number' && radius > 0 && height > 0) { return Math.pow(radius, 2) * this.pi * height } else { @@ -20,7 +20,6 @@ const miniMathLibExtended = { } } } - function cylinderVolumeAccurate(pi) { if (typeof pi === 'number' && pi > 0) { return function (radius, height) { @@ -30,6 +29,5 @@ function cylinderVolumeAccurate(pi) { throw new Error('Число Пи должно быть положительным') } } - module.exports.miniMathLibExtended = miniMathLibExtended; module.exports.cylinderVolumeAccurate = cylinderVolumeAccurate; \ No newline at end of file From 6e6436ade658b3d5eba4e41e0d7e8ea20344eb44 Mon Sep 17 00:00:00 2001 From: "DESKTOP-QOPDFPB\\ARTEMIY" Date: Sat, 23 Oct 2021 15:08:36 +0500 Subject: [PATCH 3/5] up --- topic-2/task-1/index.js | 4 ++-- topic-2/task-2/index.js | 2 +- topic-2/task-3/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/topic-2/task-1/index.js b/topic-2/task-1/index.js index 585065d..4e39bb7 100644 --- a/topic-2/task-1/index.js +++ b/topic-2/task-1/index.js @@ -10,10 +10,10 @@ */ function removeSmallest(numbers) { if (Array.isArray(numbers)) { - arr = numbers //Исходя из условий задачи, что исходный массив нельзя изменять + let arr = numbers //Исходя из условий задачи, что исходный массив нельзя изменять if (arr.every(elem => typeof elem === 'number')) { let a = +Infinity - for (i = 0; i < arr.length; i++) { + for (let i = 0; i < arr.length; i++) { if (a > arr[i]) { a = arr[i] } diff --git a/topic-2/task-2/index.js b/topic-2/task-2/index.js index a5b6b29..d8df2f9 100644 --- a/topic-2/task-2/index.js +++ b/topic-2/task-2/index.js @@ -19,7 +19,7 @@ const arrayStripped = (array, size) => { let arr = [] for (i = 0; i < a; i++) { let arr_1 = [] - for (b = 0; b < size; b++) { + for (let b = 0; b < size; b++) { if (array.length === 0) { break } diff --git a/topic-2/task-3/index.js b/topic-2/task-3/index.js index fbca53b..efb29a9 100644 --- a/topic-2/task-3/index.js +++ b/topic-2/task-3/index.js @@ -25,7 +25,7 @@ function isGroup(group) { let b = arr.length let d = Array.from(new Set(arr)).toString() if (arr.every(elem => elem === '(' || ')' || '[' || ']' || '{' || '}') && b % 2 == 0 && d === a && arr[0] != ')' && arr[0] != ']' && arr[0] != '}') { - for (i = 0; i < b; i++) { + for (let i = 0; i < b; i++) { if (group[i] === '(') { if (group[b - 1 - i] !== ')' && group[i + 1] !== ')') { return false From 447e9c154b31b4ee85f0c37fa397e83aaa19216b Mon Sep 17 00:00:00 2001 From: "DESKTOP-QOPDFPB\\ARTEMIY" Date: Sat, 23 Oct 2021 15:10:11 +0500 Subject: [PATCH 4/5] up --- topic-2/task-2/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topic-2/task-2/index.js b/topic-2/task-2/index.js index d8df2f9..9b5086c 100644 --- a/topic-2/task-2/index.js +++ b/topic-2/task-2/index.js @@ -17,7 +17,7 @@ const arrayStripped = (array, size) => { if (Number.isInteger(size) && Array.isArray(array)) { const a = array.length / size let arr = [] - for (i = 0; i < a; i++) { + for (let i = 0; i < a; i++) { let arr_1 = [] for (let b = 0; b < size; b++) { if (array.length === 0) { From 3a3eedf66c9e5dde4789c2a6d58cfc48a6d9855e Mon Sep 17 00:00:00 2001 From: "DESKTOP-QOPDFPB\\ARTEMIY" Date: Sun, 24 Oct 2021 09:57:05 +0500 Subject: [PATCH 5/5] up --- topic-2/task-2/index.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/topic-2/task-2/index.js b/topic-2/task-2/index.js index 9b5086c..6522d3c 100644 --- a/topic-2/task-2/index.js +++ b/topic-2/task-2/index.js @@ -14,21 +14,26 @@ * @returns массив разбитый на группы */ const arrayStripped = (array, size) => { - if (Number.isInteger(size) && Array.isArray(array)) { - const a = array.length / size - let arr = [] - for (let i = 0; i < a; i++) { - let arr_1 = [] - for (let b = 0; b < size; b++) { - if (array.length === 0) { - break + if (Number.isInteger(size)) { + if (!Array.isArray(array) || array.length == 0) { + return [] + } + else if (Array.isArray(array)) { + const a = array.length / size + let arr = [] + for (let i = 0; i < a; i++) { + let arr_1 = [] + for (let b = 0; b < size; b++) { + if (array.length === 0) { + break + } + arr_1.push(array[0]) + array.splice(0, 1) } - arr_1.push(array[0]) - array.splice(0, 1) + arr.push(arr_1) } - arr.push(arr_1) + return arr } - return arr } else { throw new Error('Ожидался массив и целосчисленный разделитель')