From 8504e3ba69e4bab82ff118730edeb598ffe69792 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Tue, 16 Oct 2018 21:50:30 +0500 Subject: [PATCH 01/34] Finish do abProblem, finish do centuryByYearProblem, start do colorsProblem --- warmup.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/warmup.js b/warmup.js index eefda9891..043d2f33f 100644 --- a/warmup.js +++ b/warmup.js @@ -1,5 +1,12 @@ 'use strict'; +/** + * Проверяет является ли аргумент числом + * @returns {Boolean} + */ +function isNumber(a) { + return typeof a === 'number'; +} /** * Складывает два целых числа * @param {Number} a Первое целое @@ -7,8 +14,14 @@ * @throws {TypeError} Когда в аргументы переданы не числа * @returns {Number} Сумма аргументов */ -function abProblem(a, b) { - // Ваше решение + function abProblem(a, b) { + if(!isNumber(a)){ + throw new TypeError('First argument is not a number'); + } + if(!isNumber(b)) { + throw new TypeError('Second argument is not a number'); + } + return a + b; } /** @@ -19,7 +32,12 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - // Ваше решение + if(!isNumber(year)) { + throw new TypeError('Argument is not a number'); + } + if(year < 0) { + throw new RangeError('Argument is negative') + } } /** From db0f322fa3cf07d593838fca9089dfb1f4f8a063 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Tue, 16 Oct 2018 21:51:42 +0500 Subject: [PATCH 02/34] I don't now what i did --- warmup.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/warmup.js b/warmup.js index 043d2f33f..3dd2f9434 100644 --- a/warmup.js +++ b/warmup.js @@ -2,11 +2,13 @@ /** * Проверяет является ли аргумент числом - * @returns {Boolean} + * @param Нет требований к аргументу + * @returns {Boolean} Если является числом, то true, а иначе false */ -function isNumber(a) { - return typeof a === 'number'; +function isNumber(something) { + return typeof something === 'number'; } + /** * Складывает два целых числа * @param {Number} a Первое целое @@ -38,6 +40,19 @@ function centuryByYearProblem(year) { if(year < 0) { throw new RangeError('Argument is negative') } + const YEARS_IN_CENTURY = 100; + return Math + .floor(year / YEARS_IN_CENTURY) //GetindexCenturyByYear + + 1; //GetnumberCenturyByYear +} + +/** + * определяет является ли аргумент строкой + * @param Нет требований к аргументу + * @returns {Boolean} Если является строкой, то true, а иначе false + */ + function isString(something) { + return typeof something === 'string'; } /** @@ -47,8 +62,42 @@ function centuryByYearProblem(year) { * @throws {RangeError} Когда значения цвета выходят за пределы допустимых * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ -function colorsProblem(hexColor) { - // Ваше решение + function colorsProblem(hexColor) { + if(!isString(hexColor)) { + throw new TypeError('Color in Format HEX don\'t gives as a string'); + } + const COLOR_RANGE_ERROR = new RangeError('Value of color is incorrect'); + if(hexColor.length !== 7 || hexColor[0] !== '#') { + throw COLOR_RANGE_ERROR; + } + const HEX = (function (){ + const symbols = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; + return { + Base: 16, + includes: function (symbol) { return symbols.includes(symbol)}, + + } + + })(); + + for(let i = 1; i < hexColor.length; i++) { + if(!hexSymbols.includes(hexColor[i])) { + throw COLOR_RANGE_ERROR; + } + } + let RGBColorString = '('; + const BASE_HEX = 16; + let i = 1 + while(true) { + RGBColorString += (hexSymbols.indexOf(hexColor[i]) * BASE_HEX + + hexSymbols.indexOf(hexColor[i+1])).toString(); + + if(i >= hexColor.length) { + break; + } + RGBColorString += ', '; + } + return '(' + hexSymbols.indexOf(hexColor[]) } /** From 5fc04b74a71ad51733c83ad703f2f20ad982bfb8 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Wed, 17 Oct 2018 00:49:30 +0500 Subject: [PATCH 03/34] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D1=83=20Hex=20=D0=B2?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB.=20=D0=A2=D0=B0=D0=BC=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D1=81=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BD=D0=BE=D0=B4=D0=BB?= =?UTF-8?q?=D0=B5=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB=D0=B0=D0=BC=20Hex=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=B0=20Hex=20=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=B2=D0=BE=D0=BB=D0=B0=20=D0=B2=20=D0=B4=D0=B5=D1=81?= =?UTF-8?q?=D1=8F=D1=82=D0=B8=D1=87=D0=BD=D0=BE=D0=B5=20=D1=87=D0=B8=D1=81?= =?UTF-8?q?=D0=BB=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hex.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Hex.js diff --git a/Hex.js b/Hex.js new file mode 100644 index 000000000..cdd673d2b --- /dev/null +++ b/Hex.js @@ -0,0 +1,28 @@ +'use strict' + +const HEX_SYMBOLS = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; +const HEX_BASE = 16; + +/** + * Определяет является ли символ шеснадцатиричным + * @param {String} symbol Шестнадцатиричный символ, в виде строки длины 1 + * @returns {Boolean} Когда символ шестнадцатиричный, то true, а иначе false + */ +function IsHexadimal(symbol) { + return HEX_SYMBOLS.includes(symbol); +} + +/** + * Переводит Шестнадцатиричный символ в десятичное число + * @param {String} symbol Шестнадцатиричный символ, в виде строки длины 1 + * @returns {Number} Десятичнеое число, переведённое из шестнадчатиричного символа + */ +function GetNUmberBySymbal(symbol) { + return HEX_SYMBOLS.indexOf(symbol); +} + +module.exports = { + HEX_BASE, + IsHexadimal, + GetNUmberBySymbal +} \ No newline at end of file From 5b627c8eaec6d83109df166d602c5c374c9be77d Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Wed, 17 Oct 2018 01:13:40 +0500 Subject: [PATCH 04/34] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E?= =?UTF-8?q?=20colorsProblem=20=D1=81=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89?= =?UTF-8?q?=D1=8C=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82?= =?UTF-8?q?=20=D0=B8=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20Hex.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/warmup.js b/warmup.js index 3dd2f9434..91e2399d9 100644 --- a/warmup.js +++ b/warmup.js @@ -70,18 +70,13 @@ function centuryByYearProblem(year) { if(hexColor.length !== 7 || hexColor[0] !== '#') { throw COLOR_RANGE_ERROR; } - const HEX = (function (){ - const symbols = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; - return { - Base: 16, - includes: function (symbol) { return symbols.includes(symbol)}, - - } - - })(); - + const { + BASE_HEX, + IsHexadimal, + GetNUmberBySymbal + } = require('./Hex'); for(let i = 1; i < hexColor.length; i++) { - if(!hexSymbols.includes(hexColor[i])) { + if(!IsHexadimal(hexColor[i])) { throw COLOR_RANGE_ERROR; } } @@ -89,15 +84,15 @@ function centuryByYearProblem(year) { const BASE_HEX = 16; let i = 1 while(true) { - RGBColorString += (hexSymbols.indexOf(hexColor[i]) * BASE_HEX - + hexSymbols.indexOf(hexColor[i+1])).toString(); + RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX + + GetNUmberBySymbal(hexColor[i+1])).toString(); if(i >= hexColor.length) { break; } RGBColorString += ', '; } - return '(' + hexSymbols.indexOf(hexColor[]) + return RGBColorString; } /** From aced57ff9c51fb3f530d622e86c05ec2862eae94 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Fri, 19 Oct 2018 00:29:55 +0500 Subject: [PATCH 05/34] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C=20fibanacci?= =?UTF-8?q?Problem,=20matrixProblem,=20numberSystemProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/warmup.js b/warmup.js index 91e2399d9..f4224f6ee 100644 --- a/warmup.js +++ b/warmup.js @@ -103,7 +103,25 @@ function centuryByYearProblem(year) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - // Ваше решение + if(!isNumber(n) !== 'number') { + throw new TypeError('Position in row give\'s not as a number'); + } + if(n < 0) { + throw new RangeError('Position in row not positve integer'); + } + if(n === 0 || n === 1) { + return n; + } + let q = 0; + let qPlus1 = 1; + let i = 2; + while (i < n) { + const next = q + qPlus1; + q = qPlus1; + qPlus1 = next; + i++; + } + return q + qPlus1; } /** @@ -113,7 +131,23 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - // Ваше решение + const ARRAY_2D_RANGE_ERROR = new TypeError('transfered not an 2D array'); + if(!Array.isArray(matrix)) { + throw ARRAY_2D_RANGE_ERROR; + } + for(let i = 0; i < matrix.length; i++) { + if(!Array.isArray(matrix[i])) { + throw ARRAY_2D_RANGE_ERROR; + } + } + const newMatrix = []; + const m = matrix[0].length; + const n = matrix.length; + for(let i = 0; i < m; i++) { + for(let j = 0; j < n; j++) { + newMatrix[i][j] = matrix[j][i]; + } + } } /** @@ -125,7 +159,22 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - // Ваше решение + if(!isNumber(n)) { + throw new TypeError('Transfered not a decimal number'); + } + if(!isNumber(targetNs)) { + throw new TypeError('Base of number system isn\'t a number'); + } + if(2 > targetNs || targetNs > 36) { + throw new RangeError('Base of number system not belong [2, 36]'); + } + let numbersArray = []; + do { + numbersArray.unshift(n % targetNs); + n = Math.floor(n / targetNs); + } while (n >= targetNs); + numbersArray.unshift(n); + return numbersArray.toString(); } /** @@ -134,7 +183,7 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - // Ваше решение + } /** From 47f7ea3684e0185c00c424c732bf9a2e04c01fc7 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Fri, 19 Oct 2018 01:16:46 +0500 Subject: [PATCH 06/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20ToLocaleLowerCase=20=D0=B2=20colorsProblem,=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20PhoneProblem=20=D1=81=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=80?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B2=D1=8B=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index f4224f6ee..625edfb7a 100644 --- a/warmup.js +++ b/warmup.js @@ -63,6 +63,7 @@ function centuryByYearProblem(year) { * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ function colorsProblem(hexColor) { + hexColor.toLocaleLowerCase(); if(!isString(hexColor)) { throw new TypeError('Color in Format HEX don\'t gives as a string'); } @@ -183,7 +184,10 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - + if(phoneNumber.length !== 15) { + return false; + } + return /8-800-\d{3}-\d{2}-\d{2}/.test(phoneNumber); } /** From 2a779d0b36cc7adfe6b43917850611e17b05e790 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Fri, 19 Oct 2018 13:09:49 +0500 Subject: [PATCH 07/34] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C=20smilesPro?= =?UTF-8?q?blem=20=D0=B8=20ticTacToeProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index 625edfb7a..817f67e6e 100644 --- a/warmup.js +++ b/warmup.js @@ -197,7 +197,26 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - // Ваше решение + if(!isString(text)) { + throw new TypeError('Text didn\'t transfer like a string'); + } + let amount = 0; + const smilesArray = [':-)', '(-:']; + for(let i = 0; i < text.length - 2; i++) { + for(let j = 0; j < smilesArray.length; j++) { + if(i + smilesArray[j].length <= text.length) { + let isSmile = true; + for(let k = 0; k < smilesArray[j].length; k++) { + if(text[i + k] !== smilesArray[k]) { + isSmile = false; + break; + } + } + if(isSmile) { amount++; } + } + } + } + return amount; } /** @@ -207,7 +226,34 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - // Ваше решение + let x0 = 1; + let y0 = 1; + let delta = Math.PI/4; + const iterationQuantity = Math.round(2*Math.PI / delta); + for(let i = 0; i < iterationQuantity; i++) { + const dX = Math.round(Math.cos(i*delta)); + const dY = Math.round(Math.sin(i*delta)); + if(field[x0][y0] === field[x0+dX][y0+dY] && + field[x0][y0] === field[x0-dX][x0-dY]) { + return field[x0][y0]; + } + } + x0 = 0; + y0 = 0; + delta = Math.PI/2; + const iterationQuantity = Math.round(2*Math.PI / delta); + for(let i = 0; i < iterationQuantity; i++) { + const dX = Math.round(Math.cos(-i*delta)); + const dY = Math.round(Math.sin(-i*delta)); + if(field[x0][y0] === field[x0+dX][y0+dY] && + field[x0][y0] === field[x0 + 2*dX][y0 + 2*dY]) { + return field[x0][y0]; + } + x0 += 2*dX; + y0 += 2*dY; + } + return 'draw'; + } module.exports = { From ac503294e5f92f4a64b11b6ebc6199aef02713c5 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 13:31:43 +0500 Subject: [PATCH 08/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20BASE=5FHEX?= =?UTF-8?q?=20=D0=B2=20colorsProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/warmup.js b/warmup.js index 817f67e6e..852a4e6ba 100644 --- a/warmup.js +++ b/warmup.js @@ -82,7 +82,6 @@ function centuryByYearProblem(year) { } } let RGBColorString = '('; - const BASE_HEX = 16; let i = 1 while(true) { RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX From e0e6d8c115e8dccdc81689456de6df526ee4d74b Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 13:36:12 +0500 Subject: [PATCH 09/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20iterationQua?= =?UTF-8?q?ntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 852a4e6ba..c522a9964 100644 --- a/warmup.js +++ b/warmup.js @@ -240,7 +240,7 @@ function ticTacToeProblem(field) { x0 = 0; y0 = 0; delta = Math.PI/2; - const iterationQuantity = Math.round(2*Math.PI / delta); + iterationQuantity = Math.round(2*Math.PI / delta); for(let i = 0; i < iterationQuantity; i++) { const dX = Math.round(Math.cos(-i*delta)); const dY = Math.round(Math.sin(-i*delta)); From 26e8d0c802fae4ed27d6555987fa8bf7bca88174 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 13:47:06 +0500 Subject: [PATCH 10/34] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20CodeStayle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 99 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/warmup.js b/warmup.js index c522a9964..844a07a30 100644 --- a/warmup.js +++ b/warmup.js @@ -17,12 +17,13 @@ function isNumber(something) { * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if(!isNumber(a)){ + if (!isNumber(a)){ throw new TypeError('First argument is not a number'); } - if(!isNumber(b)) { + if (!isNumber(b)) { throw new TypeError('Second argument is not a number'); } + return a + b; } @@ -34,13 +35,14 @@ function isNumber(something) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if(!isNumber(year)) { + if (!isNumber(year)) { throw new TypeError('Argument is not a number'); } - if(year < 0) { + if (year < 0) { throw new RangeError('Argument is negative') } const YEARS_IN_CENTURY = 100; + return Math .floor(year / YEARS_IN_CENTURY) //GetindexCenturyByYear + 1; //GetnumberCenturyByYear @@ -64,11 +66,11 @@ function centuryByYearProblem(year) { */ function colorsProblem(hexColor) { hexColor.toLocaleLowerCase(); - if(!isString(hexColor)) { + if (!isString(hexColor)) { throw new TypeError('Color in Format HEX don\'t gives as a string'); } const COLOR_RANGE_ERROR = new RangeError('Value of color is incorrect'); - if(hexColor.length !== 7 || hexColor[0] !== '#') { + if (hexColor.length !== 7 || hexColor[0] !== '#') { throw COLOR_RANGE_ERROR; } const { @@ -76,22 +78,23 @@ function centuryByYearProblem(year) { IsHexadimal, GetNUmberBySymbal } = require('./Hex'); - for(let i = 1; i < hexColor.length; i++) { - if(!IsHexadimal(hexColor[i])) { + for (let i = 1; i < hexColor.length; i++) { + if (!IsHexadimal(hexColor[i])) { throw COLOR_RANGE_ERROR; } } let RGBColorString = '('; let i = 1 - while(true) { + while (true) { RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX - + GetNUmberBySymbal(hexColor[i+1])).toString(); + + GetNUmberBySymbal(hexColor[i + 1])).toString(); - if(i >= hexColor.length) { + if (i >= hexColor.length) { break; } RGBColorString += ', '; } + return RGBColorString; } @@ -103,13 +106,13 @@ function centuryByYearProblem(year) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - if(!isNumber(n) !== 'number') { + if (!isNumber(n) !== 'number') { throw new TypeError('Position in row give\'s not as a number'); } - if(n < 0) { + if (n < 0) { throw new RangeError('Position in row not positve integer'); } - if(n === 0 || n === 1) { + if (n === 0 || n === 1) { return n; } let q = 0; @@ -121,6 +124,7 @@ function fibonacciProblem(n) { qPlus1 = next; i++; } + return q + qPlus1; } @@ -132,22 +136,24 @@ function fibonacciProblem(n) { */ function matrixProblem(matrix) { const ARRAY_2D_RANGE_ERROR = new TypeError('transfered not an 2D array'); - if(!Array.isArray(matrix)) { + if (!Array.isArray(matrix)) { throw ARRAY_2D_RANGE_ERROR; } - for(let i = 0; i < matrix.length; i++) { - if(!Array.isArray(matrix[i])) { + for (let i = 0; i < matrix.length; i++) { + if (!Array.isArray(matrix[i])) { throw ARRAY_2D_RANGE_ERROR; } } const newMatrix = []; const m = matrix[0].length; const n = matrix.length; - for(let i = 0; i < m; i++) { - for(let j = 0; j < n; j++) { + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { newMatrix[i][j] = matrix[j][i]; } } + + return newMatrix; } /** @@ -159,13 +165,13 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - if(!isNumber(n)) { + if (!isNumber(n)) { throw new TypeError('Transfered not a decimal number'); } - if(!isNumber(targetNs)) { + if (!isNumber(targetNs)) { throw new TypeError('Base of number system isn\'t a number'); } - if(2 > targetNs || targetNs > 36) { + if (2 > targetNs || targetNs > 36) { throw new RangeError('Base of number system not belong [2, 36]'); } let numbersArray = []; @@ -174,6 +180,7 @@ function numberSystemProblem(n, targetNs) { n = Math.floor(n / targetNs); } while (n >= targetNs); numbersArray.unshift(n); + return numbersArray.toString(); } @@ -183,7 +190,7 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - if(phoneNumber.length !== 15) { + if (phoneNumber.length !== 15) { return false; } return /8-800-\d{3}-\d{2}-\d{2}/.test(phoneNumber); @@ -196,25 +203,26 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - if(!isString(text)) { + if (!isString(text)) { throw new TypeError('Text didn\'t transfer like a string'); } let amount = 0; const smilesArray = [':-)', '(-:']; - for(let i = 0; i < text.length - 2; i++) { - for(let j = 0; j < smilesArray.length; j++) { - if(i + smilesArray[j].length <= text.length) { + for (let i = 0; i < text.length - 2; i++) { + for (let j = 0; j < smilesArray.length; j++) { + if (i + smilesArray[j].length <= text.length) { let isSmile = true; - for(let k = 0; k < smilesArray[j].length; k++) { - if(text[i + k] !== smilesArray[k]) { + for (let k = 0; k < smilesArray[j].length; k++) { + if (text[i + k] !== smilesArray[k]) { isSmile = false; break; } } - if(isSmile) { amount++; } + if (isSmile) { amount++; } } } } + return amount; } @@ -227,30 +235,31 @@ function smilesProblem(text) { function ticTacToeProblem(field) { let x0 = 1; let y0 = 1; - let delta = Math.PI/4; + let delta = Math.PI / 4; const iterationQuantity = Math.round(2*Math.PI / delta); - for(let i = 0; i < iterationQuantity; i++) { - const dX = Math.round(Math.cos(i*delta)); - const dY = Math.round(Math.sin(i*delta)); - if(field[x0][y0] === field[x0+dX][y0+dY] && - field[x0][y0] === field[x0-dX][x0-dY]) { + for (let i = 0; i < iterationQuantity; i++) { + const dX = Math.round(Math.cos(i * delta)); + const dY = Math.round(Math.sin(i * delta)); + if (field[x0][y0] === field[x0 + dX][y0 + dY] && + field[x0][y0] === field[x0 - dX][x0 - dY]) { return field[x0][y0]; } } x0 = 0; y0 = 0; - delta = Math.PI/2; - iterationQuantity = Math.round(2*Math.PI / delta); - for(let i = 0; i < iterationQuantity; i++) { - const dX = Math.round(Math.cos(-i*delta)); - const dY = Math.round(Math.sin(-i*delta)); - if(field[x0][y0] === field[x0+dX][y0+dY] && - field[x0][y0] === field[x0 + 2*dX][y0 + 2*dY]) { + delta = Math.PI / 2; + iterationQuantity = Math.round(2 * Math.PI / delta); + for (let i = 0; i < iterationQuantity; i++) { + const dX = Math.round(Math.cos(-i * delta)); + const dY = Math.round(Math.sin(-i * delta)); + if (field[x0][y0] === field[x0 + dX][y0 + dY] && + field[x0][y0] === field[x0 + 2*dX][y0 + 2*dY]) { return field[x0][y0]; } - x0 += 2*dX; - y0 += 2*dY; + x0 += 2 * dX; + y0 += 2 * dY; } + return 'draw'; } From a786f78babe5dc265c9704a8f64bed5e5a7794cb Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 13:51:42 +0500 Subject: [PATCH 11/34] =?UTF-8?q?CodeStyle=20=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/warmup.js b/warmup.js index 844a07a30..8a7d0e484 100644 --- a/warmup.js +++ b/warmup.js @@ -44,8 +44,7 @@ function centuryByYearProblem(year) { const YEARS_IN_CENTURY = 100; return Math - .floor(year / YEARS_IN_CENTURY) //GetindexCenturyByYear - + 1; //GetnumberCenturyByYear + .floor(year / YEARS_IN_CENTURY) + 1; } /** @@ -84,7 +83,7 @@ function centuryByYearProblem(year) { } } let RGBColorString = '('; - let i = 1 + let i = 1; while (true) { RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX + GetNUmberBySymbal(hexColor[i + 1])).toString(); From 9943cf923c644f1b2bba5bcb00828fce0f4ae87d Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:01:56 +0500 Subject: [PATCH 12/34] CodeStyle 1.3 --- warmup.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/warmup.js b/warmup.js index 8a7d0e484..50986fcd6 100644 --- a/warmup.js +++ b/warmup.js @@ -44,7 +44,8 @@ function centuryByYearProblem(year) { const YEARS_IN_CENTURY = 100; return Math - .floor(year / YEARS_IN_CENTURY) + 1; + .floor(year / YEARS_IN_CENTURY) + // получили индекс года + 1; // получили номер года } /** @@ -85,8 +86,8 @@ function centuryByYearProblem(year) { let RGBColorString = '('; let i = 1; while (true) { - RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX - + GetNUmberBySymbal(hexColor[i + 1])).toString(); + RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX + + GetNUmberBySymbal(hexColor[i + 1])).toString(); if (i >= hexColor.length) { break; @@ -235,7 +236,7 @@ function ticTacToeProblem(field) { let x0 = 1; let y0 = 1; let delta = Math.PI / 4; - const iterationQuantity = Math.round(2*Math.PI / delta); + const iterationQuantity = Math.round(2 * Math.PI / delta); for (let i = 0; i < iterationQuantity; i++) { const dX = Math.round(Math.cos(i * delta)); const dY = Math.round(Math.sin(i * delta)); @@ -252,7 +253,7 @@ function ticTacToeProblem(field) { const dX = Math.round(Math.cos(-i * delta)); const dY = Math.round(Math.sin(-i * delta)); if (field[x0][y0] === field[x0 + dX][y0 + dY] && - field[x0][y0] === field[x0 + 2*dX][y0 + 2*dY]) { + field[x0][y0] === field[x0 + 2 * dX][y0 + 2 * dY]) { return field[x0][y0]; } x0 += 2 * dX; @@ -260,7 +261,6 @@ function ticTacToeProblem(field) { } return 'draw'; - } module.exports = { From 7a1d8ec368b4610eeab541cd36e257a1af794b7f Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:11:25 +0500 Subject: [PATCH 13/34] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20(CodeStyle)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hex.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Hex.js b/Hex.js index cdd673d2b..f90930a85 100644 --- a/Hex.js +++ b/Hex.js @@ -8,7 +8,7 @@ const HEX_BASE = 16; * @param {String} symbol Шестнадцатиричный символ, в виде строки длины 1 * @returns {Boolean} Когда символ шестнадцатиричный, то true, а иначе false */ -function IsHexadimal(symbol) { +function isHexadimal(symbol) { return HEX_SYMBOLS.includes(symbol); } @@ -17,12 +17,12 @@ function IsHexadimal(symbol) { * @param {String} symbol Шестнадцатиричный символ, в виде строки длины 1 * @returns {Number} Десятичнеое число, переведённое из шестнадчатиричного символа */ -function GetNUmberBySymbal(symbol) { +function getNUmberBySymbal(symbol) { return HEX_SYMBOLS.indexOf(symbol); } module.exports = { HEX_BASE, - IsHexadimal, - GetNUmberBySymbal -} \ No newline at end of file + isHexadimal, + getNUmberBySymbal +} From 970e83a4f92d535f0200b9f725741980c7f75544 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:13:17 +0500 Subject: [PATCH 14/34] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BD=D0=B0=D0=B7=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20ColorsProblem=20(CodeStyle)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/warmup.js b/warmup.js index 50986fcd6..b48fb11b4 100644 --- a/warmup.js +++ b/warmup.js @@ -75,19 +75,19 @@ function centuryByYearProblem(year) { } const { BASE_HEX, - IsHexadimal, - GetNUmberBySymbal + isHexadimal, + getNUmberBySymbal } = require('./Hex'); for (let i = 1; i < hexColor.length; i++) { - if (!IsHexadimal(hexColor[i])) { + if (!isHexadimal(hexColor[i])) { throw COLOR_RANGE_ERROR; } } let RGBColorString = '('; let i = 1; while (true) { - RGBColorString += (GetNUmberBySymbal(hexColor[i]) * BASE_HEX + - GetNUmberBySymbal(hexColor[i + 1])).toString(); + RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + + getNUmberBySymbal(hexColor[i + 1])).toString(); if (i >= hexColor.length) { break; From 6febbb2420065bbb5de0a38655592e842d035295 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:25:36 +0500 Subject: [PATCH 15/34] CodeStyle 1.4 --- warmup.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/warmup.js b/warmup.js index b48fb11b4..904d6a000 100644 --- a/warmup.js +++ b/warmup.js @@ -16,14 +16,14 @@ function isNumber(something) { * @throws {TypeError} Когда в аргументы переданы не числа * @returns {Number} Сумма аргументов */ - function abProblem(a, b) { - if (!isNumber(a)){ +function abProblem(a, b) { + if (!isNumber(a)) { throw new TypeError('First argument is not a number'); } if (!isNumber(b)) { throw new TypeError('Second argument is not a number'); } - + return a + b; } @@ -39,10 +39,10 @@ function centuryByYearProblem(year) { throw new TypeError('Argument is not a number'); } if (year < 0) { - throw new RangeError('Argument is negative') + throw new RangeError('Argument is negative'); } const YEARS_IN_CENTURY = 100; - + return Math .floor(year / YEARS_IN_CENTURY) + // получили индекс года 1; // получили номер года @@ -53,7 +53,7 @@ function centuryByYearProblem(year) { * @param Нет требований к аргументу * @returns {Boolean} Если является строкой, то true, а иначе false */ - function isString(something) { +function isString(something) { return typeof something === 'string'; } @@ -64,7 +64,7 @@ function centuryByYearProblem(year) { * @throws {RangeError} Когда значения цвета выходят за пределы допустимых * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ - function colorsProblem(hexColor) { +function colorsProblem(hexColor) { hexColor.toLocaleLowerCase(); if (!isString(hexColor)) { throw new TypeError('Color in Format HEX don\'t gives as a string'); @@ -87,14 +87,14 @@ function centuryByYearProblem(year) { let i = 1; while (true) { RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + - getNUmberBySymbal(hexColor[i + 1])).toString(); + getNUmberBySymbal(hexColor[i + 1])).toString(); if (i >= hexColor.length) { break; } RGBColorString += ', '; } - + return RGBColorString; } @@ -124,7 +124,7 @@ function fibonacciProblem(n) { qPlus1 = next; i++; } - + return q + qPlus1; } @@ -152,7 +152,7 @@ function matrixProblem(matrix) { newMatrix[i][j] = matrix[j][i]; } } - + return newMatrix; } @@ -180,7 +180,7 @@ function numberSystemProblem(n, targetNs) { n = Math.floor(n / targetNs); } while (n >= targetNs); numbersArray.unshift(n); - + return numbersArray.toString(); } @@ -222,7 +222,7 @@ function smilesProblem(text) { } } } - + return amount; } @@ -259,7 +259,7 @@ function ticTacToeProblem(field) { x0 += 2 * dX; y0 += 2 * dY; } - + return 'draw'; } From 7dff91ae26ec243c7e020e2a8a8470d1c64530e1 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:35:47 +0500 Subject: [PATCH 16/34] CodeStyle 1.5 --- Hex.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Hex.js b/Hex.js index f90930a85..b6c51c941 100644 --- a/Hex.js +++ b/Hex.js @@ -1,6 +1,7 @@ 'use strict' -const HEX_SYMBOLS = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; +const HEX_SYMBOLS = + ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; const HEX_BASE = 16; /** From c3cc110b899024ed541dc4a2840a4bf6fa45b15e Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:36:16 +0500 Subject: [PATCH 17/34] CodeStyle 1.6 --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index 904d6a000..5d099daa4 100644 --- a/warmup.js +++ b/warmup.js @@ -2,7 +2,7 @@ /** * Проверяет является ли аргумент числом - * @param Нет требований к аргументу + * @param {} Нет требований к аргументу * @returns {Boolean} Если является числом, то true, а иначе false */ function isNumber(something) { @@ -50,7 +50,7 @@ function centuryByYearProblem(year) { /** * определяет является ли аргумент строкой - * @param Нет требований к аргументу + * @param {} Нет требований к аргументу * @returns {Boolean} Если является строкой, то true, а иначе false */ function isString(something) { From 0573469a903707254e593fcc81a01d7f3d0e50d6 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:41:00 +0500 Subject: [PATCH 18/34] CodeStyle 1.7 --- Hex.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Hex.js b/Hex.js index b6c51c941..eac1c2504 100644 --- a/Hex.js +++ b/Hex.js @@ -1,6 +1,6 @@ -'use strict' +'use strict'; -const HEX_SYMBOLS = +const HEX_SYMBOLS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; const HEX_BASE = 16; @@ -26,4 +26,4 @@ module.exports = { HEX_BASE, isHexadimal, getNUmberBySymbal -} +}; From 4b15e446a1069f24d0b79878ec5f5e79778a40e3 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:45:30 +0500 Subject: [PATCH 19/34] CodeStyle 1.8 --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index 5d099daa4..201bf4c9f 100644 --- a/warmup.js +++ b/warmup.js @@ -2,7 +2,7 @@ /** * Проверяет является ли аргумент числом - * @param {} Нет требований к аргументу + * @param {Number} Нет требований к аргументу * @returns {Boolean} Если является числом, то true, а иначе false */ function isNumber(something) { @@ -50,7 +50,7 @@ function centuryByYearProblem(year) { /** * определяет является ли аргумент строкой - * @param {} Нет требований к аргументу + * @param {String} Нет требований к аргументу * @returns {Boolean} Если является строкой, то true, а иначе false */ function isString(something) { From a8f33c0e02f2b8163356ce95b27642d0c6971bf1 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 14:52:07 +0500 Subject: [PATCH 20/34] CodeStyle 1.8 --- warmup.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/warmup.js b/warmup.js index 201bf4c9f..18a19c4a9 100644 --- a/warmup.js +++ b/warmup.js @@ -2,7 +2,7 @@ /** * Проверяет является ли аргумент числом - * @param {Number} Нет требований к аргументу + * @param {Number} something Нет требований к аргументу * @returns {Boolean} Если является числом, то true, а иначе false */ function isNumber(something) { @@ -50,7 +50,7 @@ function centuryByYearProblem(year) { /** * определяет является ли аргумент строкой - * @param {String} Нет требований к аргументу + * @param {String} something Нет требований к аргументу * @returns {Boolean} Если является строкой, то true, а иначе false */ function isString(something) { @@ -85,7 +85,7 @@ function colorsProblem(hexColor) { } let RGBColorString = '('; let i = 1; - while (true) { + while () { RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + getNUmberBySymbal(hexColor[i + 1])).toString(); @@ -193,6 +193,7 @@ function phoneProblem(phoneNumber) { if (phoneNumber.length !== 15) { return false; } + return /8-800-\d{3}-\d{2}-\d{2}/.test(phoneNumber); } @@ -218,7 +219,9 @@ function smilesProblem(text) { break; } } - if (isSmile) { amount++; } + if (isSmile) { + amount++; + } } } } From 99851b710633df9b4464ae359f73deb84a149180 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 15:00:32 +0500 Subject: [PATCH 21/34] CodeStyle 1.9 --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 18a19c4a9..24d9c818b 100644 --- a/warmup.js +++ b/warmup.js @@ -85,7 +85,7 @@ function colorsProblem(hexColor) { } let RGBColorString = '('; let i = 1; - while () { + while { RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + getNUmberBySymbal(hexColor[i + 1])).toString(); From 4cc2dd1301df40bd14f5cde5132f5fa7dac68129 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 15:06:11 +0500 Subject: [PATCH 22/34] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BA=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BD=D0=B0=20While(true)=20{},=20=D0=B8=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B5=20=D0=BF=D1=83=D1=81=D0=BA=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index 24d9c818b..b0f9373b5 100644 --- a/warmup.js +++ b/warmup.js @@ -85,10 +85,10 @@ function colorsProblem(hexColor) { } let RGBColorString = '('; let i = 1; - while { + const flag = true; + while (flag) { RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + getNUmberBySymbal(hexColor[i + 1])).toString(); - if (i >= hexColor.length) { break; } From dcbb9e1b4a385167cb6e065f405b4f53bd7eb28c Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 15:13:03 +0500 Subject: [PATCH 23/34] CodeStyle 1.10 --- warmup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/warmup.js b/warmup.js index b0f9373b5..69a5f3482 100644 --- a/warmup.js +++ b/warmup.js @@ -220,7 +220,7 @@ function smilesProblem(text) { } } if (isSmile) { - amount++; + amount++; } } } @@ -244,7 +244,7 @@ function ticTacToeProblem(field) { const dX = Math.round(Math.cos(i * delta)); const dY = Math.round(Math.sin(i * delta)); if (field[x0][y0] === field[x0 + dX][y0 + dY] && - field[x0][y0] === field[x0 - dX][x0 - dY]) { + field[x0][y0] === field[x0 - dX][x0 - dY]) { return field[x0][y0]; } } @@ -256,7 +256,7 @@ function ticTacToeProblem(field) { const dX = Math.round(Math.cos(-i * delta)); const dY = Math.round(Math.sin(-i * delta)); if (field[x0][y0] === field[x0 + dX][y0 + dY] && - field[x0][y0] === field[x0 + 2 * dX][y0 + 2 * dY]) { + field[x0][y0] === field[x0 + 2 * dX][y0 + 2 * dY]) { return field[x0][y0]; } x0 += 2 * dX; From 60abd43777e67d5a72c52ae4402688d9d7ede492 Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Fri, 19 Oct 2018 15:58:03 +0500 Subject: [PATCH 24/34] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BB=20SmilesProblem,=20numberSystemProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/warmup.js b/warmup.js index 69a5f3482..0e47e16c6 100644 --- a/warmup.js +++ b/warmup.js @@ -76,7 +76,7 @@ function colorsProblem(hexColor) { const { BASE_HEX, isHexadimal, - getNUmberBySymbal + getNumberBySymbal } = require('./Hex'); for (let i = 1; i < hexColor.length; i++) { if (!isHexadimal(hexColor[i])) { @@ -87,8 +87,8 @@ function colorsProblem(hexColor) { let i = 1; const flag = true; while (flag) { - RGBColorString += (getNUmberBySymbal(hexColor[i]) * BASE_HEX + - getNUmberBySymbal(hexColor[i + 1])).toString(); + RGBColorString += (getNumberBySymbal(hexColor[i]) * BASE_HEX + + getNumberBySymbal(hexColor[i + 1])).toString(); if (i >= hexColor.length) { break; } @@ -174,14 +174,8 @@ function numberSystemProblem(n, targetNs) { if (2 > targetNs || targetNs > 36) { throw new RangeError('Base of number system not belong [2, 36]'); } - let numbersArray = []; - do { - numbersArray.unshift(n % targetNs); - n = Math.floor(n / targetNs); - } while (n >= targetNs); - numbersArray.unshift(n); - return numbersArray.toString(); + return n.toString(targetNs); } /** @@ -207,25 +201,11 @@ function smilesProblem(text) { if (!isString(text)) { throw new TypeError('Text didn\'t transfer like a string'); } - let amount = 0; const smilesArray = [':-)', '(-:']; - for (let i = 0; i < text.length - 2; i++) { - for (let j = 0; j < smilesArray.length; j++) { - if (i + smilesArray[j].length <= text.length) { - let isSmile = true; - for (let k = 0; k < smilesArray[j].length; k++) { - if (text[i + k] !== smilesArray[k]) { - isSmile = false; - break; - } - } - if (isSmile) { - amount++; - } - } - } - } - + let amount = 0; + smilesArray.forEach(function (smile) { + amount += text.split(smile).length - 1; + }); return amount; } From 49f08024774c4e84501e982ac131b416427b9aba Mon Sep 17 00:00:00 2001 From: plazma_drink Date: Fri, 19 Oct 2018 16:00:47 +0500 Subject: [PATCH 25/34] =?UTF-8?q?=D0=97=D0=B0=D0=B1=D1=8B=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D1=82=D1=8C=20=D1=81=D0=BA=D0=B0=D1=87=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9.=20=D0=9F=D0=BE=D0=B7=D0=B4=D0=BD?= =?UTF-8?q?=D0=BE.=20=D0=94=D0=B5=D0=BB=D0=B0=D1=8E=20=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hex.js b/Hex.js index eac1c2504..0795cedd5 100644 --- a/Hex.js +++ b/Hex.js @@ -26,4 +26,4 @@ module.exports = { HEX_BASE, isHexadimal, getNUmberBySymbal -}; +}; \ No newline at end of file From 32d18c592581d5572cea51f118299986ac4c6eee Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 16:09:11 +0500 Subject: [PATCH 26/34] CodeStyle 1.11 --- warmup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/warmup.js b/warmup.js index 0e47e16c6..b2d632ef1 100644 --- a/warmup.js +++ b/warmup.js @@ -206,6 +206,7 @@ function smilesProblem(text) { smilesArray.forEach(function (smile) { amount += text.split(smile).length - 1; }); + return amount; } From 2fed0944317355320509cd5b7dfdfbb30cc5ac0b Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 16:16:25 +0500 Subject: [PATCH 27/34] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D1=83=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=86=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=B2=20Hex.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hex.js b/Hex.js index 0795cedd5..eac1c2504 100644 --- a/Hex.js +++ b/Hex.js @@ -26,4 +26,4 @@ module.exports = { HEX_BASE, isHexadimal, getNUmberBySymbal -}; \ No newline at end of file +}; From faedfa8231872d1b3e8260560c1214fec642c018 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 16:24:14 +0500 Subject: [PATCH 28/34] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BD=D0=B0=D0=B4=D0=BB=D0=B5=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20[2,=2036]=20=D0=B2=20numberSys?= =?UTF-8?q?temProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index b2d632ef1..5503623f3 100644 --- a/warmup.js +++ b/warmup.js @@ -171,7 +171,9 @@ function numberSystemProblem(n, targetNs) { if (!isNumber(targetNs)) { throw new TypeError('Base of number system isn\'t a number'); } - if (2 > targetNs || targetNs > 36) { + const maxNumberSystem = 36; + const minNumberSystem = 2; + if ((targetNs - minNumberSystem) * (maxNumberSystem - targetNs) < 0) { throw new RangeError('Base of number system not belong [2, 36]'); } From 900e6fc1af465542e16423a859c6066c79fb4f5b Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 16:59:59 +0500 Subject: [PATCH 29/34] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D1=81=D1=82=D1=83=D0=BF=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20231=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=2012.=20=D0=91=D1=8B=D0=BB=D0=BE=2015.=20=D0=98=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20ColorsProblem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/warmup.js b/warmup.js index 5503623f3..a9b8a2bfa 100644 --- a/warmup.js +++ b/warmup.js @@ -65,12 +65,12 @@ function isString(something) { * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ function colorsProblem(hexColor) { - hexColor.toLocaleLowerCase(); - if (!isString(hexColor)) { + const lowerHexColor = hexColor.toLocaleLowerCase(); + if (!isString(lowerHexColor)) { throw new TypeError('Color in Format HEX don\'t gives as a string'); } const COLOR_RANGE_ERROR = new RangeError('Value of color is incorrect'); - if (hexColor.length !== 7 || hexColor[0] !== '#') { + if (lowerHexColor.length !== 7 || lowerHexColor[0] !== '#') { throw COLOR_RANGE_ERROR; } const { @@ -78,24 +78,17 @@ function colorsProblem(hexColor) { isHexadimal, getNumberBySymbal } = require('./Hex'); - for (let i = 1; i < hexColor.length; i++) { - if (!isHexadimal(hexColor[i])) { + for (let i = 1; i < lowerHexColor.length; i++) { + if (!isHexadimal(lowerHexColor[i])) { throw COLOR_RANGE_ERROR; } } - let RGBColorString = '('; - let i = 1; - const flag = true; - while (flag) { - RGBColorString += (getNumberBySymbal(hexColor[i]) * BASE_HEX + - getNumberBySymbal(hexColor[i + 1])).toString(); - if (i >= hexColor.length) { - break; - } - RGBColorString += ', '; - } + lowerHexColor = lowerHexColor.split('#').shift(); + const number1 = lowerHexColor[0] * BASE_HEX + lowerHexColor[1]; + const number2 = lowerHexColor[2] * BASE_HEX + lowerHexColor[3]; + const number3 = lowerHexColor[4] * BASE_HEX + lowerHexColor[5]; - return RGBColorString; + return '(${number1}, ${number2}, {number3})'; } /** @@ -228,7 +221,7 @@ function ticTacToeProblem(field) { const dY = Math.round(Math.sin(i * delta)); if (field[x0][y0] === field[x0 + dX][y0 + dY] && field[x0][y0] === field[x0 - dX][x0 - dY]) { - return field[x0][y0]; + return field[x0][y0]; } } x0 = 0; From 0d5978bbe859e3836db58b4bbe58518133753ada Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 17:08:28 +0500 Subject: [PATCH 30/34] =?UTF-8?q?=D0=92=20colorsProblem=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8F=D0=BB=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=B1=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index a9b8a2bfa..7c6bc4365 100644 --- a/warmup.js +++ b/warmup.js @@ -87,8 +87,7 @@ function colorsProblem(hexColor) { const number1 = lowerHexColor[0] * BASE_HEX + lowerHexColor[1]; const number2 = lowerHexColor[2] * BASE_HEX + lowerHexColor[3]; const number3 = lowerHexColor[4] * BASE_HEX + lowerHexColor[5]; - - return '(${number1}, ${number2}, {number3})'; + return '(' + number1 + ',' + number2 + ',' + number3 + ')'; } /** From e15c4b69c0845a388bf550865d7821725982f051 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 17:11:48 +0500 Subject: [PATCH 31/34] =?UTF-8?q?=D0=97=D0=B0=D0=B1=D1=8B=D0=BB=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20getNumberBySymbal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/warmup.js b/warmup.js index 7c6bc4365..38e5abe9d 100644 --- a/warmup.js +++ b/warmup.js @@ -84,9 +84,10 @@ function colorsProblem(hexColor) { } } lowerHexColor = lowerHexColor.split('#').shift(); - const number1 = lowerHexColor[0] * BASE_HEX + lowerHexColor[1]; - const number2 = lowerHexColor[2] * BASE_HEX + lowerHexColor[3]; - const number3 = lowerHexColor[4] * BASE_HEX + lowerHexColor[5]; + const number1 = getNumberBySymbal(lowerHexColor[0]) * BASE_HEX + getNumberBySymbal(lowerHexColor[1]); + const number2 = getNumberBySymbal(lowerHexColor[2]) * BASE_HEX + getNumberBySymbal(lowerHexColor[3]); + const number3 = getNumberBySymbal(lowerHexColor[4]) * BASE_HEX + getNumberBySymbal(lowerHexColor[5]); + return '(' + number1 + ',' + number2 + ',' + number3 + ')'; } From f3773533d1b3967721c5b6b45682de06d3a3508b Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 17:19:53 +0500 Subject: [PATCH 32/34] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB=20getNumberBySymbal=20?= =?UTF-8?q?=D0=B2=20getNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/warmup.js b/warmup.js index 38e5abe9d..135beef50 100644 --- a/warmup.js +++ b/warmup.js @@ -76,7 +76,7 @@ function colorsProblem(hexColor) { const { BASE_HEX, isHexadimal, - getNumberBySymbal + getNumber } = require('./Hex'); for (let i = 1; i < lowerHexColor.length; i++) { if (!isHexadimal(lowerHexColor[i])) { @@ -84,10 +84,9 @@ function colorsProblem(hexColor) { } } lowerHexColor = lowerHexColor.split('#').shift(); - const number1 = getNumberBySymbal(lowerHexColor[0]) * BASE_HEX + getNumberBySymbal(lowerHexColor[1]); - const number2 = getNumberBySymbal(lowerHexColor[2]) * BASE_HEX + getNumberBySymbal(lowerHexColor[3]); - const number3 = getNumberBySymbal(lowerHexColor[4]) * BASE_HEX + getNumberBySymbal(lowerHexColor[5]); - + const number1 = getNumber(lowerHexColor[0]) * BASE_HEX + getNumber(lowerHexColor[1]); + const number2 = getNumber(lowerHexColor[2]) * BASE_HEX + getNumber(lowerHexColor[3]); + const number3 = getNumber(lowerHexColor[4]) * BASE_HEX + getNumber(lowerHexColor[5]); return '(' + number1 + ',' + number2 + ',' + number3 + ')'; } From 88770d14ef14ab67ab1e1a2cf0316eda67190114 Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 17:21:11 +0500 Subject: [PATCH 33/34] =?UTF-8?q?=D0=A2=D0=BE=D0=B6=D0=B5,=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B8=20=D0=B2=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4?= =?UTF-8?q?=D1=83=D1=89=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hex.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Hex.js b/Hex.js index eac1c2504..1d9c912a1 100644 --- a/Hex.js +++ b/Hex.js @@ -18,12 +18,12 @@ function isHexadimal(symbol) { * @param {String} symbol Шестнадцатиричный символ, в виде строки длины 1 * @returns {Number} Десятичнеое число, переведённое из шестнадчатиричного символа */ -function getNUmberBySymbal(symbol) { +function getNumber(symbol) { return HEX_SYMBOLS.indexOf(symbol); } module.exports = { HEX_BASE, isHexadimal, - getNUmberBySymbal + getNumber }; From ff2df319bdbdfbde6a5119724f0d55db26caa2ea Mon Sep 17 00:00:00 2001 From: SVladislavD Date: Fri, 19 Oct 2018 17:23:51 +0500 Subject: [PATCH 34/34] CodeStyle 1.12 --- warmup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/warmup.js b/warmup.js index 135beef50..33a16ce38 100644 --- a/warmup.js +++ b/warmup.js @@ -87,6 +87,7 @@ function colorsProblem(hexColor) { const number1 = getNumber(lowerHexColor[0]) * BASE_HEX + getNumber(lowerHexColor[1]); const number2 = getNumber(lowerHexColor[2]) * BASE_HEX + getNumber(lowerHexColor[3]); const number3 = getNumber(lowerHexColor[4]) * BASE_HEX + getNumber(lowerHexColor[5]); + return '(' + number1 + ',' + number2 + ',' + number3 + ')'; }