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; + diff --git a/topic-1/task-2/index.js b/topic-1/task-2/index.js index 093141c..fa7b8fd 100644 --- a/topic-1/task-2/index.js +++ b/topic-1/task-2/index.js @@ -11,7 +11,23 @@ * @param {*} array массив * @returns удвоенный массив */ - function calculateDoubleArray(array) { -} + function calculateDoubleArray(array) +{ + let doubledArray = []; + for (let i = 0; i < array.length; i++) + { + if (array[i] === 0) + { + doubledArray.splice(i,0); + } + else + { + doubledArray.push(array[i]); + doubledArray.push(array[i]); + } + + } + return doubledArray; +} module.exports.calculateDoubleArray = calculateDoubleArray; \ No newline at end of file diff --git a/topic-1/task-3/index.js b/topic-1/task-3/index.js index 7e12c79..47bba3a 100644 --- a/topic-1/task-3/index.js +++ b/topic-1/task-3/index.js @@ -10,6 +10,19 @@ */ function factorial(n) { + if (n < 0){ + throw new Error("Value must be more than zero"); + } + else if (n === 0) { + return 1; + } + else { + let result = n; + while (n > 1) { + n--; + result *= n; + } + return result; + } } - module.exports.factorial = factorial; \ No newline at end of file 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