From 6568b6af10cc182c4552274326b9c50dc20cbc89 Mon Sep 17 00:00:00 2001 From: alexeyvolhin <82944068+alexeyvolhin@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:53:09 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=92=D0=BE=D0=BB=D1=8C=D1=85=D0=B8=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topic-1/task-1/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/topic-1/task-1/index.js b/topic-1/task-1/index.js index d76557c..5f4bf05 100644 --- a/topic-1/task-1/index.js +++ b/topic-1/task-1/index.js @@ -10,7 +10,10 @@ * @returns */ - function isTriangle(a, b, c) { + function isTriangle(a, b, c) +{ + return ((a + b > c) && (a + c > b) && (b + c > a)) } -module.exports.isTriangle = isTriangle; \ No newline at end of file +module.exports.isTriangle = isTriangle; + From 72499b22814a90b86dcfe69bf5cd96e7fc0611de Mon Sep 17 00:00:00 2001 From: alexeyvolhin <82944068+alexeyvolhin@users.noreply.github.com> Date: Sun, 19 Sep 2021 18:49:33 +0500 Subject: [PATCH 2/5] Second --- topic-1/task-2/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/topic-1/task-2/index.js b/topic-1/task-2/index.js index 093141c..2102159 100644 --- a/topic-1/task-2/index.js +++ b/topic-1/task-2/index.js @@ -11,7 +11,18 @@ * @param {*} array массив * @returns удвоенный массив */ - function calculateDoubleArray(array) { -} + function calculateDoubleArray(array) +{ + let doubledArray = []; + for (i = 0; i < array.length; i++) + { + if (array[i] !==0) + { + doubledArray.push(array[i]); + doubledArray.push(array[i]); + } + } + return doubledArray; +} module.exports.calculateDoubleArray = calculateDoubleArray; \ No newline at end of file From 7b3c8f6bb824bff86f33fa9246719104a31af356 Mon Sep 17 00:00:00 2001 From: alexeyvolhin <82944068+alexeyvolhin@users.noreply.github.com> Date: Sun, 19 Sep 2021 23:39:12 +0500 Subject: [PATCH 3/5] Third --- topic-1/task-3/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/topic-1/task-3/index.js b/topic-1/task-3/index.js index 7e12c79..1866296 100644 --- a/topic-1/task-3/index.js +++ b/topic-1/task-3/index.js @@ -10,6 +10,14 @@ */ function factorial(n) { + if (n < 0){ + throw new Error("Value must be more than zero"); + } + else if (n === 0) { + return 1; + } + else { + return n * factorial(n - 1); + } } - module.exports.factorial = factorial; \ No newline at end of file From 06d650faef8247ed8f1c8bd1139bfc40dc39db46 Mon Sep 17 00:00:00 2001 From: alexeyvolhin <82944068+alexeyvolhin@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:33:28 +0500 Subject: [PATCH 4/5] 2nd and 3rd corrected --- topic-1/task-2/index.js | 9 +++++++-- topic-1/task-3/index.js | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/topic-1/task-2/index.js b/topic-1/task-2/index.js index 2102159..fa7b8fd 100644 --- a/topic-1/task-2/index.js +++ b/topic-1/task-2/index.js @@ -15,13 +15,18 @@ function calculateDoubleArray(array) { let doubledArray = []; - for (i = 0; i < array.length; i++) + for (let i = 0; i < array.length; i++) { - if (array[i] !==0) + if (array[i] === 0) + { + doubledArray.splice(i,0); + } + else { doubledArray.push(array[i]); doubledArray.push(array[i]); } + } return doubledArray; } diff --git a/topic-1/task-3/index.js b/topic-1/task-3/index.js index 1866296..47bba3a 100644 --- a/topic-1/task-3/index.js +++ b/topic-1/task-3/index.js @@ -17,7 +17,12 @@ function factorial(n) { return 1; } else { - return n * factorial(n - 1); + let result = n; + while (n > 1) { + n--; + result *= n; + } + return result; } } module.exports.factorial = factorial; \ No newline at end of file From 1e1358fda2a3c939fb82040f84e897539b0c14e7 Mon Sep 17 00:00:00 2001 From: alexeyvolhin <82944068+alexeyvolhin@users.noreply.github.com> Date: Mon, 20 Sep 2021 21:21:54 +0500 Subject: [PATCH 5/5] 4th --- topic-1/task-4/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/topic-1/task-4/index.js b/topic-1/task-4/index.js index da33ee2..0864e6e 100644 --- a/topic-1/task-4/index.js +++ b/topic-1/task-4/index.js @@ -7,6 +7,13 @@ * @return {number} Количество уникальных имён * */ function countUniqueName(nameArray) { + let names = []; + for (let word of nameArray) { + let highWord = word.toUpperCase(); + if (!names.includes(highWord)) { + names.push(highWord); + } + } + return names.length; } - module.exports.countUniqueName = countUniqueName; \ No newline at end of file