From 22f62f9787452149e32c41c259ab8cf248cebf46 Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 16:19:20 +0500 Subject: [PATCH 1/6] Update warmup.js --- warmup.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 9 deletions(-) diff --git a/warmup.js b/warmup.js index eefda9891..fe2dc9f48 100644 --- a/warmup.js +++ b/warmup.js @@ -8,7 +8,12 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - // Ваше решение + + if (!Number.isInteger(a) || !Number.isInteger(b)){ + throw new TypeError(''); + } + + return a + b; } /** @@ -19,7 +24,16 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - // Ваше решение + + if (!Number.isInteger(year)) { + throw new TypeError(''); + } + if (year < 0){ + throw new RangeError(''); + } + + const century = year / 100; + return century % 100 != 0 ? century + 1 : century; } /** @@ -30,7 +44,20 @@ function centuryByYearProblem(year) { * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ function colorsProblem(hexColor) { - // Ваше решение + + if (typeof (hexColor) !== 'string') { + throw new TypeError(''); + } + + if (!(/#[0-9a-fA-F]{6}/g).test(hexColor)) { + throw new RangeError(''); + } + + const red = parseInt(hexColor.substring(1, 3), 16); + const green = parseInt(hexColor.substring(3, 5), 16); + const blue = parseInt(hexColor.substring(5, 7), 16); + + return '(${red}, ${green}, ${blue})'; } /** @@ -41,7 +68,24 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - // Ваше решение + + if (typeof(n) !== 'number') { + throw new TypeError(''); + } + + if (n <= 0 || !Number.isInteger(n)) { + throw new RangeError(''); + } + + var left = 1; + var right = 1; + for (var i = 3; i <= n; i++) { + const current = left + right; + left = right; + right = current; + } + + return right; } /** @@ -51,7 +95,20 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - // Ваше решение + + if (matrix.length === 0 || !Array.isArray(matrix) || !matrix.every(Array.isArray)) { + throw new TypeError(''); + } + + var newMarix = []; + for (var i = 0; i < matrix[0].length; i++) { + newMarix[i] = []; + for (var j = 0; j < matrix.length; j++) { + newMarix[i][j] = matrix[j][i]; + } + } + + return newMarix; } /** @@ -63,7 +120,15 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - // Ваше решение + + if (typeof(n) !== 'number' || !Number.isInteger(targetNs)) { + throw new TypeError(''); + } + if (targetNs < 2 || targetNs > 36) { + throw new RangeError(''); + } + + return n.toString(targetNs); } /** @@ -72,7 +137,12 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - // Ваше решение + + if (isNotString(phoneNumber)) { + throw new TypeError(''); + } + + return (/^8-800-\d{3}-\d{2}-\d{2}$/).test(phoneNumber); } /** @@ -82,7 +152,16 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - // Ваше решение + + var smileCount = 0; + for (var i = 0; i < text.length; i++) { + const temp = text.substr(i, 3); + if (temp === '(-:' || temp === ':-)') { + smileCount++; + } + } + + return smileCount; } /** @@ -92,7 +171,22 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - // Ваше решение + + for (var i = 0; i < field[0].length; ++i) { + if (field[0][i] === field[1][i] && field[0][i] === field[2][i]) { + return field[0][i]; + } + if (field[i][0] === field[i][1] && field[i][0] === field[i][2]) { + return field[i][0]; + } + } + + if ((field[1][1] === field[0][0] && field[1][1] === field[2][2]) || + (field[1][1] === field[0][2] && field[2][0] === field[1][1])) { + return field[1][1]; + } + + return 'draw'; } module.exports = { From f8ae49c4d28f3e977536f53804c8f520ef7b988d Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 16:48:28 +0500 Subject: [PATCH 2/6] Update warmup.js --- warmup.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/warmup.js b/warmup.js index fe2dc9f48..c80bbc645 100644 --- a/warmup.js +++ b/warmup.js @@ -9,7 +9,7 @@ */ function abProblem(a, b) { - if (!Number.isInteger(a) || !Number.isInteger(b)){ + if (!Number.isInteger(a) || !Number.isInteger(b)) { throw new TypeError(''); } @@ -25,15 +25,16 @@ function abProblem(a, b) { */ function centuryByYearProblem(year) { - if (!Number.isInteger(year)) { + if (!Number.isInteger(year)){ throw new TypeError(''); } - if (year < 0){ + if (year < 0) { throw new RangeError(''); } const century = year / 100; - return century % 100 != 0 ? century + 1 : century; + + return century % 100 !== 0 ? century + 1 : century; } /** @@ -48,16 +49,16 @@ function colorsProblem(hexColor) { if (typeof (hexColor) !== 'string') { throw new TypeError(''); } - - if (!(/#[0-9a-fA-F]{6}/g).test(hexColor)) { + + if (!(/#[0-9a-fA-F]{6}/g).test(hexColor)){ throw new RangeError(''); } const red = parseInt(hexColor.substring(1, 3), 16); const green = parseInt(hexColor.substring(3, 5), 16); const blue = parseInt(hexColor.substring(5, 7), 16); - - return '(${red}, ${green}, ${blue})'; + + return '(' + red + ', ' + green + ', ' + blue + ')'; } /** @@ -68,15 +69,13 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - if (typeof(n) !== 'number') { throw new TypeError(''); } - if (n <= 0 || !Number.isInteger(n)) { throw new RangeError(''); } - + var left = 1; var right = 1; for (var i = 3; i <= n; i++) { @@ -95,7 +94,6 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - if (matrix.length === 0 || !Array.isArray(matrix) || !matrix.every(Array.isArray)) { throw new TypeError(''); } @@ -120,7 +118,6 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - if (typeof(n) !== 'number' || !Number.isInteger(targetNs)) { throw new TypeError(''); } @@ -137,8 +134,7 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - - if (isNotString(phoneNumber)) { + if (typeof (phoneNumber) !== 'string') { throw new TypeError(''); } @@ -152,7 +148,6 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - var smileCount = 0; for (var i = 0; i < text.length; i++) { const temp = text.substr(i, 3); @@ -171,7 +166,6 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - for (var i = 0; i < field[0].length; ++i) { if (field[0][i] === field[1][i] && field[0][i] === field[2][i]) { return field[0][i]; @@ -180,7 +174,7 @@ function ticTacToeProblem(field) { return field[i][0]; } } - + if ((field[1][1] === field[0][0] && field[1][1] === field[2][2]) || (field[1][1] === field[0][2] && field[2][0] === field[1][1])) { return field[1][1]; From e907aff0d575dd27ff1ff01c665fe5aa451fb3b9 Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 16:50:16 +0500 Subject: [PATCH 3/6] Update warmup.js --- warmup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warmup.js b/warmup.js index c80bbc645..5f1ae1594 100644 --- a/warmup.js +++ b/warmup.js @@ -25,7 +25,7 @@ function abProblem(a, b) { */ function centuryByYearProblem(year) { - if (!Number.isInteger(year)){ + if (!Number.isInteger(year)) { throw new TypeError(''); } if (year < 0) { @@ -50,7 +50,7 @@ function colorsProblem(hexColor) { throw new TypeError(''); } - if (!(/#[0-9a-fA-F]{6}/g).test(hexColor)){ + if (!(/#[0-9a-fA-F]{6}/g).test(hexColor)) { throw new RangeError(''); } From c27215686aad91a413abe4516f2ab13bd3a5823d Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 16:54:56 +0500 Subject: [PATCH 4/6] Update warmup.js --- warmup.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/warmup.js b/warmup.js index 5f1ae1594..cc83a53e4 100644 --- a/warmup.js +++ b/warmup.js @@ -32,9 +32,7 @@ function centuryByYearProblem(year) { throw new RangeError(''); } - const century = year / 100; - - return century % 100 !== 0 ? century + 1 : century; + return Math.floor((year - 1) / 100) + 1; } /** From 4210000638efe6a23bea22d186f4ff121e1ffcf6 Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 17:00:39 +0500 Subject: [PATCH 5/6] Update warmup.js --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index cc83a53e4..93a98d09f 100644 --- a/warmup.js +++ b/warmup.js @@ -13,7 +13,7 @@ function abProblem(a, b) { throw new TypeError(''); } - return a + b; + return parseInt(a) + parseInt(b);; } /** From 191166e3226a8a14c5cb25a2d678fe112175a4bd Mon Sep 17 00:00:00 2001 From: Demond98 <33758699+Demond98@users.noreply.github.com> Date: Fri, 19 Oct 2018 17:05:14 +0500 Subject: [PATCH 6/6] Update warmup.js --- warmup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmup.js b/warmup.js index 93a98d09f..7312dd033 100644 --- a/warmup.js +++ b/warmup.js @@ -13,7 +13,7 @@ function abProblem(a, b) { throw new TypeError(''); } - return parseInt(a) + parseInt(b);; + return parseInt(a) + parseInt(b); } /**