From fc86ef4955f88775c72a03d0f3f386dddfc8fe43 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Tue, 16 Oct 2018 15:26:42 +0500 Subject: [PATCH 01/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D1=80=D0=B5=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/warmup.js b/warmup.js index eefda9891..c93e219ea 100644 --- a/warmup.js +++ b/warmup.js @@ -8,7 +8,9 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - // Ваше решение + if (typeof(a) != "number" || typeof(b) != "number") + throw new TypeError(); + return a + b; } /** @@ -19,7 +21,11 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - // Ваше решение + if (typeof(year) != "number") + throw new TypeError(); + if (year < 0) + throw new RangeError(); + return Math.trunc(year / 100) + 1; } /** @@ -29,8 +35,19 @@ function centuryByYearProblem(year) { * @throws {RangeError} Когда значения цвета выходят за пределы допустимых * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ + + function colorsProblem(hexColor) { - // Ваше решение + if (typeof(hexColor) != "string") + throw new TypeError(); + first = parseInt(hexColor[1] + hexColor[2]); + second = parseInt(hexColor[3] + hexColor[4]); + third = parseInt(hexColor[5] + hexColor[6]); + if (first > 255 || second > 255 || third > 255) + throw new RangeError; + return "(" + first.toString() + ", ", + + second.toString() + ", " + + third.toString() + ")"; } /** @@ -41,7 +58,10 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - // Ваше решение + a = [1, 1]; + for (i = 2; i < n; i++) + a.push(a[i - 1] + a[i - 2]); + return a[n + 1]; } /** @@ -51,7 +71,15 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - // Ваше решение + if (!Array.isArray(matrix)) + throw new TypeError(); + for (i = 0; i < matrix.length; i++) + if (!Array.isArray(matrix[i])) + throw new TypeError(); + for (i = 0; i < matrix.length; i++) + for (j = 0; j < matrix[i].length; j++) + ans[j, i] = matrix[i, j]; + return ans; } /** @@ -63,7 +91,11 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - // Ваше решение + if (typeof(n) != "number" || typeof(targetNs) != "number") + throw TypeError(); + if (targetNs < 2 || targetNs > 36) + throw RangeError(); + return n.toString(targetNs); } /** @@ -72,7 +104,7 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - // Ваше решение + return phoneNumber.search("^8–800–\d\d\d–\d\d–\d\d$") != -1; } /** @@ -82,7 +114,20 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - // Ваше решение + if (typeof(text) != "string") + throw new TypeError(); + ans = 0; + rSmile = "(-:"; + lSmile = ":-)"; + for (i = 0; i < text.length - 2; i++) + { + tmp = ""; + for (j = 0 ; j < 3; j++) + tmp += text[i + j]; + if (tmp == rSmile || tmp == lSmile) + ans++; + } + return ans; } /** @@ -92,7 +137,28 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - // Ваше решение + for (i = 0; i < 3; i++) + { + if (field[i, 0] == field[i, 1] + && field[i, 0] == field[i, 2]) + return field[i, 0]; + } + + for (i = 0; i < 3; i++) + { + if (field[0, i] == field[1, i] + && field[0, i] == field[2, i]) + return field[0, i]; + } + if (field[0, 2] == field[1, 1] + && field[1, 1] == field[2, 0]) + return field[0, 2]; + + if (field[0, 0] == field[1, 1] + && field[1, 1] == field[2, 2]) + return field[0, 0]; + + return "draw"; } module.exports = { From a3f1cb23614485a35a57b384c5b716b05a64e3b7 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Tue, 16 Oct 2018 15:47:46 +0500 Subject: [PATCH 02/17] Update warmup.js --- warmup.js | 107 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/warmup.js b/warmup.js index c93e219ea..0f164765e 100644 --- a/warmup.js +++ b/warmup.js @@ -8,8 +8,11 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if (typeof(a) != "number" || typeof(b) != "number") + if (typeof(a) !== 'number' || typeof(b) !== 'number') + { throw new TypeError(); + } + return a + b; } @@ -21,10 +24,15 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if (typeof(year) != "number") - throw new TypeError(); + if (typeof(year) !== 'number') + { + throw new TypeError(); + } if (year < 0) - throw new RangeError(); + { + throw new RangeError(); + } + return Math.trunc(year / 100) + 1; } @@ -38,16 +46,21 @@ function centuryByYearProblem(year) { function colorsProblem(hexColor) { - if (typeof(hexColor) != "string") + if (typeof(hexColor) !== 'string') + { throw new TypeError(); - first = parseInt(hexColor[1] + hexColor[2]); - second = parseInt(hexColor[3] + hexColor[4]); - third = parseInt(hexColor[5] + hexColor[6]); + } + var first = parseInt(hexColor[1] + hexColor[2]); + var second = parseInt(hexColor[3] + hexColor[4]); + var third = parseInt(hexColor[5] + hexColor[6]); if (first > 255 || second > 255 || third > 255) - throw new RangeError; - return "(" + first.toString() + ", ", - + second.toString() + ", " - + third.toString() + ")"; + { + throw new RangeError(); + } + + return '(' + first.toString() + + ', ', + second.toString() + + ', ' + third.toString() + ')'; } /** @@ -58,9 +71,12 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - a = [1, 1]; - for (i = 2; i < n; i++) + var a = [1, 1]; + for (var i = 2; i < n; i++) + { a.push(a[i - 1] + a[i - 2]); + } + return a[n + 1]; } @@ -72,13 +88,25 @@ function fibonacciProblem(n) { */ function matrixProblem(matrix) { if (!Array.isArray(matrix)) - throw new TypeError(); - for (i = 0; i < matrix.length; i++) + { + throw new TypeError(); + } + for (var i = 0; i < matrix.length; i++) + { if (!Array.isArray(matrix[i])) + { throw new TypeError(); + } + } + var ans; for (i = 0; i < matrix.length; i++) + { for (j = 0; j < matrix[i].length; j++) + { ans[j, i] = matrix[i, j]; + } + } + return ans; } @@ -91,10 +119,16 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - if (typeof(n) != "number" || typeof(targetNs) != "number") + if (typeof(n) !== 'number' || + typeof(targetNs) !== 'number') + { throw TypeError(); + } if (targetNs < 2 || targetNs > 36) + { throw RangeError(); + } + return n.toString(targetNs); } @@ -104,7 +138,8 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - return phoneNumber.search("^8–800–\d\d\d–\d\d–\d\d$") != -1; + + return phoneNumber.search("^8–800–\\d\\d\\d–\\d\\d–\\d\\d$") !== -1; } /** @@ -114,19 +149,22 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - if (typeof(text) != "string") + if (typeof(text) !== 'string') + { throw new TypeError(); - ans = 0; - rSmile = "(-:"; - lSmile = ":-)"; - for (i = 0; i < text.length - 2; i++) + } + var ans = 0; + var rSmile = "(-:"; + var lSmile = ":-)"; + for (var i = 0; i < text.length - 2; i++) { - tmp = ""; - for (j = 0 ; j < 3; j++) + var tmp = ""; + for (var j = 0 ; j < 3; j++) tmp += text[i + j]; if (tmp == rSmile || tmp == lSmile) ans++; } + return ans; } @@ -137,26 +175,37 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - for (i = 0; i < 3; i++) + for (var i = 0; i < 3; i++) { if (field[i, 0] == field[i, 1] && field[i, 0] == field[i, 2]) + { + return field[i, 0]; + } } - for (i = 0; i < 3; i++) + for (var i = 0; i < 3; i++) { if (field[0, i] == field[1, i] && field[0, i] == field[2, i]) + { + return field[0, i]; + } } if (field[0, 2] == field[1, 1] && field[1, 1] == field[2, 0]) - return field[0, 2]; + { + + return field[0, 2]; + } if (field[0, 0] == field[1, 1] && field[1, 1] == field[2, 2]) - return field[0, 0]; + { + return field[0, 0]; + } return "draw"; } From 170ab9c8f1aec16c85e57bb6905034d1affc64c3 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Tue, 16 Oct 2018 16:04:20 +0500 Subject: [PATCH 03/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmup.js | 71 ++++++++++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/warmup.js b/warmup.js index 0f164765e..84ba127c2 100644 --- a/warmup.js +++ b/warmup.js @@ -8,8 +8,7 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if (typeof(a) !== 'number' || typeof(b) !== 'number') - { + if (typeof(a) !== 'number' || typeof(b) !== 'number'){ throw new TypeError(); } @@ -24,12 +23,10 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if (typeof(year) !== 'number') - { + if (typeof(year) !== 'number'){ throw new TypeError(); } - if (year < 0) - { + if (year < 0){ throw new RangeError(); } @@ -46,15 +43,13 @@ function centuryByYearProblem(year) { function colorsProblem(hexColor) { - if (typeof(hexColor) !== 'string') - { + if (typeof(hexColor) !== 'string'){ throw new TypeError(); } var first = parseInt(hexColor[1] + hexColor[2]); var second = parseInt(hexColor[3] + hexColor[4]); var third = parseInt(hexColor[5] + hexColor[6]); - if (first > 255 || second > 255 || third > 255) - { + if (first > 255 || second > 255 || third > 255){ throw new RangeError(); } @@ -72,8 +67,7 @@ function colorsProblem(hexColor) { */ function fibonacciProblem(n) { var a = [1, 1]; - for (var i = 2; i < n; i++) - { + for (var i = 2; i < n; i++){ a.push(a[i - 1] + a[i - 2]); } @@ -87,22 +81,17 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - if (!Array.isArray(matrix)) - { + if (!Array.isArray(matrix)){ throw new TypeError(); } - for (var i = 0; i < matrix.length; i++) - { - if (!Array.isArray(matrix[i])) - { + for (var i = 0; i < matrix.length; i++){ + if (!Array.isArray(matrix[i])){ throw new TypeError(); } } var ans; - for (i = 0; i < matrix.length; i++) - { - for (j = 0; j < matrix[i].length; j++) - { + for (var i = 0; i < matrix.length; i++){ + for (var j = 0; j < matrix[i].length; j++){ ans[j, i] = matrix[i, j]; } } @@ -120,12 +109,10 @@ function matrixProblem(matrix) { */ function numberSystemProblem(n, targetNs) { if (typeof(n) !== 'number' || - typeof(targetNs) !== 'number') - { + typeof(targetNs) !== 'number'){ throw TypeError(); } - if (targetNs < 2 || targetNs > 36) - { + if (targetNs < 2 || targetNs > 36){ throw RangeError(); } @@ -149,20 +136,20 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - if (typeof(text) !== 'string') - { + if (typeof(text) !== 'string'){ throw new TypeError(); } var ans = 0; var rSmile = "(-:"; var lSmile = ":-)"; - for (var i = 0; i < text.length - 2; i++) - { + for (var i = 0; i < text.length - 2; i++){ var tmp = ""; - for (var j = 0 ; j < 3; j++) + for (var j = 0 ; j < 3; j++){ tmp += text[i + j]; - if (tmp == rSmile || tmp == lSmile) + } + if (tmp == rSmile || tmp == lSmile){ ans++; + } } return ans; @@ -175,35 +162,29 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - for (var i = 0; i < 3; i++) - { - if (field[i, 0] == field[i, 1] - && field[i, 0] == field[i, 2]) - { + for (var i = 0; i < 3; i++){ + if (field[i, 0] === field[i, 1] + && field[i, 0] === field[i, 2]){ return field[i, 0]; } } - for (var i = 0; i < 3; i++) - { + for (var i = 0; i < 3; i++){ if (field[0, i] == field[1, i] - && field[0, i] == field[2, i]) - { + && field[0, i] == field[2, i]){ return field[0, i]; } } if (field[0, 2] == field[1, 1] - && field[1, 1] == field[2, 0]) - { + && field[1, 1] == field[2, 0]){ return field[0, 2]; } if (field[0, 0] == field[1, 1] - && field[1, 1] == field[2, 2]) - { + && field[1, 1] == field[2, 2]){ return field[0, 0]; } From 84472b1fd40e2efd1f5f464ab1edbc46b139c65b Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Tue, 16 Oct 2018 16:20:31 +0500 Subject: [PATCH 04/17] Update warmup.js --- warmup.js | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/warmup.js b/warmup.js index 84ba127c2..46a98a711 100644 --- a/warmup.js +++ b/warmup.js @@ -8,7 +8,7 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if (typeof(a) !== 'number' || typeof(b) !== 'number'){ + if (typeof(a) !== 'number' || typeof(b) !== 'number'){ throw new TypeError(); } @@ -23,10 +23,10 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if (typeof(year) !== 'number'){ + if (typeof(year) !== 'number') { throw new TypeError(); } - if (year < 0){ + if (year < 0) { throw new RangeError(); } @@ -43,13 +43,13 @@ function centuryByYearProblem(year) { function colorsProblem(hexColor) { - if (typeof(hexColor) !== 'string'){ + if (typeof(hexColor) !== 'string') { throw new TypeError(); } var first = parseInt(hexColor[1] + hexColor[2]); var second = parseInt(hexColor[3] + hexColor[4]); var third = parseInt(hexColor[5] + hexColor[6]); - if (first > 255 || second > 255 || third > 255){ + if (first > 255 || second > 255 || third > 255) { throw new RangeError(); } @@ -67,7 +67,7 @@ function colorsProblem(hexColor) { */ function fibonacciProblem(n) { var a = [1, 1]; - for (var i = 2; i < n; i++){ + for (var i = 2; i < n; i++) { a.push(a[i - 1] + a[i - 2]); } @@ -81,18 +81,18 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - if (!Array.isArray(matrix)){ + if (!Array.isArray(matrix)) { throw new TypeError(); } - for (var i = 0; i < matrix.length; i++){ - if (!Array.isArray(matrix[i])){ + for (var i = 0; i < matrix.length; i++) { + if (!Array.isArray(matrix[i])) { throw new TypeError(); } } var ans; - for (var i = 0; i < matrix.length; i++){ - for (var j = 0; j < matrix[i].length; j++){ - ans[j, i] = matrix[i, j]; + for (var i = 0; i < matrix.length; i++) { + for (var j = 0; j < matrix[i].length; j++) { + ans[j][i] = matrix[i][j]; } } @@ -109,11 +109,11 @@ function matrixProblem(matrix) { */ function numberSystemProblem(n, targetNs) { if (typeof(n) !== 'number' || - typeof(targetNs) !== 'number'){ - throw TypeError(); + typeof(targetNs) !== 'number') { + throw new TypeError(); } - if (targetNs < 2 || targetNs > 36){ - throw RangeError(); + if (targetNs < 2 || targetNs > 36) { + throw new RangeError(); } return n.toString(targetNs); @@ -136,18 +136,18 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - if (typeof(text) !== 'string'){ + if (typeof(text) !== 'string') { throw new TypeError(); } var ans = 0; - var rSmile = "(-:"; - var lSmile = ":-)"; - for (var i = 0; i < text.length - 2; i++){ - var tmp = ""; - for (var j = 0 ; j < 3; j++){ + var rSmile = '(-:'; + var lSmile = ':-)'; + for (var i = 0; i < text.length - 2; i++) { + var tmp = ''; + for (var j = 0; j < 3; j++) { tmp += text[i + j]; } - if (tmp == rSmile || tmp == lSmile){ + if (tmp === rSmile || tmp === lSmile) { ans++; } } @@ -162,33 +162,33 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - for (var i = 0; i < 3; i++){ - if (field[i, 0] === field[i, 1] - && field[i, 0] === field[i, 2]){ + for (var i = 0; i < 3; i++) { + if (field[i][0] === field[i][1] && + field[i][0] === field[i][2]) { - return field[i, 0]; + return field[i][0]; } } - for (var i = 0; i < 3; i++){ - if (field[0, i] == field[1, i] - && field[0, i] == field[2, i]){ + for (var i = 0; i < 3; i++) { + if (field[0][i] === field[1][i] && + field[0][i] === field[2][i]) { - return field[0, i]; + return field[0][i]; } } - if (field[0, 2] == field[1, 1] - && field[1, 1] == field[2, 0]){ - - return field[0, 2]; - } + if (field[0][2] === field[1][1] && + field[1][1] === field[2][0]) { + + return field[0][2]; + } - if (field[0, 0] == field[1, 1] - && field[1, 1] == field[2, 2]){ - return field[0, 0]; - } + if (field[0][0] === field[1][1] && + field[1][1] === field[2][2]) { + return field[0][0]; + } - return "draw"; + return 'draw'; } module.exports = { From 3a89e4bff7af294fbf74aded434f3b4b1759723f Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:00:53 +0500 Subject: [PATCH 05/17] Update warmup.js --- warmup.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/warmup.js b/warmup.js index 46a98a711..18b23c780 100644 --- a/warmup.js +++ b/warmup.js @@ -8,8 +8,8 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if (typeof(a) !== 'number' || typeof(b) !== 'number'){ - throw new TypeError(); + if (typeof(a) !== 'number' || typeof(b) !== 'number') { + throw new TypeError(); } return a + b; @@ -52,9 +52,8 @@ function colorsProblem(hexColor) { if (first > 255 || second > 255 || third > 255) { throw new RangeError(); } - - return '(' + first.toString() + - ', ', + second.toString() + + return '(' + first.toString() + + ', ', + second.toString() + ', ' + third.toString() + ')'; } @@ -84,14 +83,16 @@ function matrixProblem(matrix) { if (!Array.isArray(matrix)) { throw new TypeError(); } - for (var i = 0; i < matrix.length; i++) { + var i; + var j; + for (i = 0; i < matrix.length; i++) { if (!Array.isArray(matrix[i])) { throw new TypeError(); } } var ans; - for (var i = 0; i < matrix.length; i++) { - for (var j = 0; j < matrix[i].length; j++) { + for (i = 0; i < matrix.length; i++) { + for (j = 0; j < matrix[i].length; j++) { ans[j][i] = matrix[i][j]; } } @@ -108,7 +109,7 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - if (typeof(n) !== 'number' || + if (typeof(n) !== 'number' || typeof(targetNs) !== 'number') { throw new TypeError(); } @@ -126,7 +127,7 @@ function numberSystemProblem(n, targetNs) { */ function phoneProblem(phoneNumber) { - return phoneNumber.search("^8–800–\\d\\d\\d–\\d\\d–\\d\\d$") !== -1; + return phoneNumber.search('^8–800–\\d\\d\\d–\\d\\d–\\d\\d$') !== -1; } /** @@ -165,7 +166,7 @@ function ticTacToeProblem(field) { for (var i = 0; i < 3; i++) { if (field[i][0] === field[i][1] && field[i][0] === field[i][2]) { - + return field[i][0]; } } @@ -173,7 +174,7 @@ function ticTacToeProblem(field) { for (var i = 0; i < 3; i++) { if (field[0][i] === field[1][i] && field[0][i] === field[2][i]) { - + return field[0][i]; } } @@ -191,7 +192,7 @@ function ticTacToeProblem(field) { return 'draw'; } -module.exports = { +/*module.exports = { abProblem, centuryByYearProblem, colorsProblem, @@ -201,4 +202,4 @@ module.exports = { phoneProblem, smilesProblem, ticTacToeProblem -}; +};*/ From d35d5747d56917da49aa34ea803db55ab1b7b55e Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:05:06 +0500 Subject: [PATCH 06/17] Update warmup.js --- warmup.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/warmup.js b/warmup.js index 18b23c780..028406867 100644 --- a/warmup.js +++ b/warmup.js @@ -163,7 +163,8 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - for (var i = 0; i < 3; i++) { + var i; + for (i = 0; i < 3; i++) { if (field[i][0] === field[i][1] && field[i][0] === field[i][2]) { @@ -171,7 +172,7 @@ function ticTacToeProblem(field) { } } - for (var i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { if (field[0][i] === field[1][i] && field[0][i] === field[2][i]) { @@ -192,7 +193,7 @@ function ticTacToeProblem(field) { return 'draw'; } -/*module.exports = { +module.exports = { abProblem, centuryByYearProblem, colorsProblem, @@ -202,4 +203,4 @@ function ticTacToeProblem(field) { phoneProblem, smilesProblem, ticTacToeProblem -};*/ +}; From cd6cde0c98839b8a20ca6eff705e36726a518244 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:15:34 +0500 Subject: [PATCH 07/17] Update warmup.js --- warmup.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/warmup.js b/warmup.js index 028406867..a662d76b8 100644 --- a/warmup.js +++ b/warmup.js @@ -9,7 +9,7 @@ */ function abProblem(a, b) { if (typeof(a) !== 'number' || typeof(b) !== 'number') { - throw new TypeError(); + throw new TypeError(); } return a + b; @@ -52,8 +52,9 @@ function colorsProblem(hexColor) { if (first > 255 || second > 255 || third > 255) { throw new RangeError(); } + return '(' + first.toString() + - ', ', + second.toString() + + ', ' + second.toString() + ', ' + third.toString() + ')'; } @@ -162,6 +163,7 @@ function smilesProblem(text) { * @param {(('x' | 'o')[])[]} field Игровое поле 3x3 завершённой игры * @returns {'x' | 'o' | 'draw'} Результат игры */ + function ticTacToeProblem(field) { var i; for (i = 0; i < 3; i++) { @@ -170,9 +172,6 @@ function ticTacToeProblem(field) { return field[i][0]; } - } - - for (i = 0; i < 3; i++) { if (field[0][i] === field[1][i] && field[0][i] === field[2][i]) { @@ -181,12 +180,12 @@ function ticTacToeProblem(field) { } if (field[0][2] === field[1][1] && field[1][1] === field[2][0]) { - + return field[0][2]; } - if (field[0][0] === field[1][1] && field[1][1] === field[2][2]) { + return field[0][0]; } From fe9afbf57a816be6509f6a9e6ac19a434bfac15b Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:23:35 +0500 Subject: [PATCH 08/17] Update warmup.js --- warmup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/warmup.js b/warmup.js index a662d76b8..947953f53 100644 --- a/warmup.js +++ b/warmup.js @@ -46,9 +46,9 @@ function colorsProblem(hexColor) { if (typeof(hexColor) !== 'string') { throw new TypeError(); } - var first = parseInt(hexColor[1] + hexColor[2]); - var second = parseInt(hexColor[3] + hexColor[4]); - var third = parseInt(hexColor[5] + hexColor[6]); + var first = parseInt(hexColor[1] + hexColor[2], 16); + var second = parseInt(hexColor[3] + hexColor[4], 16); + var third = parseInt(hexColor[5] + hexColor[6], 16); if (first > 255 || second > 255 || third > 255) { throw new RangeError(); } @@ -71,7 +71,7 @@ function fibonacciProblem(n) { a.push(a[i - 1] + a[i - 2]); } - return a[n + 1]; + return a[n - 1]; } /** @@ -128,7 +128,7 @@ function numberSystemProblem(n, targetNs) { */ function phoneProblem(phoneNumber) { - return phoneNumber.search('^8–800–\\d\\d\\d–\\d\\d–\\d\\d$') !== -1; + return phoneNumber.search('^8-800-\\d\\d\\d-\\d\\d-\\d\\d$') !== -1; } /** From 36eb7833757f0692fe315541255b5e554c74bd07 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:28:19 +0500 Subject: [PATCH 09/17] Update warmup.js --- warmup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 947953f53..dfcbbbaff 100644 --- a/warmup.js +++ b/warmup.js @@ -86,12 +86,14 @@ function matrixProblem(matrix) { } var i; var j; + var ans = []; for (i = 0; i < matrix.length; i++) { if (!Array.isArray(matrix[i])) { throw new TypeError(); } + ans.push([]) } - var ans; + for (i = 0; i < matrix.length; i++) { for (j = 0; j < matrix[i].length; j++) { ans[j][i] = matrix[i][j]; From 880f7caa9494d2fb9284e985e74bfb4b3a513d5d Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:31:39 +0500 Subject: [PATCH 10/17] Update warmup.js --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index dfcbbbaff..cb9a452a5 100644 --- a/warmup.js +++ b/warmup.js @@ -91,9 +91,9 @@ function matrixProblem(matrix) { if (!Array.isArray(matrix[i])) { throw new TypeError(); } - ans.push([]) + ans.push([]); } - + for (i = 0; i < matrix.length; i++) { for (j = 0; j < matrix[i].length; j++) { ans[j][i] = matrix[i][j]; From 72545670befe2f48e369168b6a8786259d290831 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:44:57 +0500 Subject: [PATCH 11/17] Update warmup.js --- warmup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index cb9a452a5..47d6cbc14 100644 --- a/warmup.js +++ b/warmup.js @@ -120,7 +120,7 @@ function numberSystemProblem(n, targetNs) { throw new RangeError(); } - return n.toString(targetNs); + return n.toString(targetNs).toLowerCase(); } /** @@ -129,6 +129,8 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { + if (typeof(phoneNumber) !== "string") + throw new TypeError(); return phoneNumber.search('^8-800-\\d\\d\\d-\\d\\d-\\d\\d$') !== -1; } From e88adfdda805ef6af6aba6f63fbeeb9cc2f3cb41 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 15:48:17 +0500 Subject: [PATCH 12/17] Update warmup.js --- warmup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 47d6cbc14..9e1a80d9a 100644 --- a/warmup.js +++ b/warmup.js @@ -129,8 +129,9 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - if (typeof(phoneNumber) !== "string") + if (typeof(phoneNumber) !== 'string') { throw new TypeError(); + } return phoneNumber.search('^8-800-\\d\\d\\d-\\d\\d-\\d\\d$') !== -1; } From ad626a604766ff3a0e0f9fc5ad7dcde1ffe26eed Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:03:36 +0500 Subject: [PATCH 13/17] Update warmup.js --- warmup.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 9e1a80d9a..c1df07685 100644 --- a/warmup.js +++ b/warmup.js @@ -66,6 +66,12 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { + if (typeof(n) !== 'number') { + throw new TypeError(); + } + if (n <= 0 || !isInteger(n)) { + throw new RangeError(); + } var a = [1, 1]; for (var i = 2; i < n; i++) { a.push(a[i - 1] + a[i - 2]); @@ -113,7 +119,8 @@ function matrixProblem(matrix) { */ function numberSystemProblem(n, targetNs) { if (typeof(n) !== 'number' || - typeof(targetNs) !== 'number') { + typeof(targetNs) !== 'number' || + !isInteger(targetNs)) { throw new TypeError(); } if (targetNs < 2 || targetNs > 36) { From d31d65808a7437123dd6c0bb6c656960bf35d6a6 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:08:18 +0500 Subject: [PATCH 14/17] Update warmup.js --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index c1df07685..ec9d91f0b 100644 --- a/warmup.js +++ b/warmup.js @@ -69,7 +69,7 @@ function fibonacciProblem(n) { if (typeof(n) !== 'number') { throw new TypeError(); } - if (n <= 0 || !isInteger(n)) { + if (n <= 0 || Number.isInteger(n)) { throw new RangeError(); } var a = [1, 1]; @@ -120,7 +120,7 @@ function matrixProblem(matrix) { function numberSystemProblem(n, targetNs) { if (typeof(n) !== 'number' || typeof(targetNs) !== 'number' || - !isInteger(targetNs)) { + !Number.isInteger(targetNs)) { throw new TypeError(); } if (targetNs < 2 || targetNs > 36) { From 04efb2f918662889285c00f17994a4663ec169bd Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:12:26 +0500 Subject: [PATCH 15/17] Update warmup.js --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index ec9d91f0b..b5f6fd810 100644 --- a/warmup.js +++ b/warmup.js @@ -69,7 +69,7 @@ function fibonacciProblem(n) { if (typeof(n) !== 'number') { throw new TypeError(); } - if (n <= 0 || Number.isInteger(n)) { + if (n <= 0 || !Number.isInteger(n)) { throw new RangeError(); } var a = [1, 1]; From 8b7157d25e2198f8c7d811087177083b854228a1 Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:28:07 +0500 Subject: [PATCH 16/17] Update warmup.js --- warmup.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index b5f6fd810..f66dd8a43 100644 --- a/warmup.js +++ b/warmup.js @@ -8,7 +8,8 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - if (typeof(a) !== 'number' || typeof(b) !== 'number') { + if (typeof(a) !== 'number' || typeof(b) !== 'number' || + !Number.isInteger(a) || !Number.isInteger(b)) { throw new TypeError(); } @@ -23,7 +24,8 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if (typeof(year) !== 'number') { + if (typeof(year) !== 'number'|| + !Number.isInteger(year)) { throw new TypeError(); } if (year < 0) { From 07d274ec95991f565341beb931088ccd48e9386d Mon Sep 17 00:00:00 2001 From: AndrewGomzyakov <32879688+AndrewGomzyakov@users.noreply.github.com> Date: Sun, 21 Oct 2018 16:30:38 +0500 Subject: [PATCH 17/17] Update warmup.js --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index f66dd8a43..b2e3ca914 100644 --- a/warmup.js +++ b/warmup.js @@ -24,7 +24,7 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - if (typeof(year) !== 'number'|| + if (typeof(year) !== 'number' || !Number.isInteger(year)) { throw new TypeError(); }