From f3c606a17f584a04f25d8bcc0e033dd4627f2565 Mon Sep 17 00:00:00 2001 From: ainail Date: Fri, 19 Oct 2018 00:34:36 +0500 Subject: [PATCH 1/6] first try --- warmup.js | 130 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 115 insertions(+), 15 deletions(-) diff --git a/warmup.js b/warmup.js index eefda9891..36f506f5a 100644 --- a/warmup.js +++ b/warmup.js @@ -1,3 +1,4 @@ +/* eslint-disable space-infix-ops,no-trailing-spaces */ 'use strict'; /** @@ -8,7 +9,11 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - // Ваше решение + if (typeof(a) !== 'number' || typeof(b) !== 'number') { + throw new TypeError (); + } + + return a + b; } /** @@ -19,7 +24,14 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { - // Ваше решение + if (typeof(year) !== 'number') { + throw new TypeError(); + } + if (year < 1) { + throw new RangeError(); + } + + return Math.trunc(year / 100) + 1; } /** @@ -30,7 +42,17 @@ function centuryByYearProblem(year) { * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ function colorsProblem(hexColor) { - // Ваше решение + const expression = new RegExp(/^#[0-9A-Fa-f]{6}$/g); + if (typeof(hexColor) !== 'string') { + throw new TypeError(); + } + if (!expression.test(hexColor)) { + throw new RangeError(); + } + + return ('(' + parseInt(hexColor.substring(1, 3), 16) + ', ' + + parseInt(hexColor.substring(3, 5), 16) + ', ' + + parseInt(hexColor.substring(5, 7), 16) + ')'); } /** @@ -41,17 +63,42 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - // Ваше решение + if (typeof(n) !== 'number') { + throw new TypeError(); + } + if (n < 1 || n !== Math.trunc(n)) { + throw new RangeError(); + } + let last = 1; + let current = 1; + let next = 1; + if (n > 2) { + for (let i = 3; i <= n; i++) { + next = current + last; + last = current; + current = next; + } + } + + return current; } -/** - * Транспонирует матрицу - * @param {(Any[])[]} matrix Матрица размерности MxN - * @throws {TypeError} Когда в функцию передаётся не двумерный массив - * @returns {(Any[])[]} Транспонированная матрица размера NxM - */ + function matrixProblem(matrix) { - // Ваше решение + if (!Array.isArray(matrix) || matrix.length === 0) { + throw new TypeError(); + } + let m = matrix.length; + let n = matrix[0].length; + const ans = []; + for (let i = 0; i < n; i++) { + ans[i] = []; + for (let j = 0; j < m; j++) { + ans[i][j] = matrix[j][i]; + } + } + + return ans; } /** @@ -63,7 +110,14 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - // Ваше решение + if (typeof(n) !== 'number' || typeof(targetNs) !== 'number') { + throw new TypeError(); + } + if (targetNs < 2 || targetNs > 36) { + throw new RangeError(); + } + + return n.toString(targetNs); } /** @@ -72,7 +126,10 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - // Ваше решение + const expression = new RegExp(/^8-800-[0-9]{3}-[0-9]{2}-[0-9]{2}$/g); + + return (typeof(phoneNumber) === 'string' && phoneNumber.length === 15 && + expression.test(phoneNumber)); } /** @@ -82,7 +139,22 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - // Ваше решение + if (typeof(text) !== 'string') { + throw new TypeError(); + } + let count = 0; + for (let i = 0; i < text.length - 2; i++) { + if (text[i] === '(' && text[i + 1] === '-' && text[i + 2] === ':') { + count++; + i += 2; + } + if (text[i] === ':' && text[i + 1] === '-' && text[i + 2] === ')') { + count++; + i += 2; + } + } + + return count; } /** @@ -92,7 +164,35 @@ function smilesProblem(text) { * @returns {'x' | 'o' | 'draw'} Результат игры */ function ticTacToeProblem(field) { - // Ваше решение + const winner = 'draw'; + if (check(field) !== 'draw') { + return (check(field)); + } else if (check(matrixProblem(field)) !== 'draw') { + return check(matrixProblem(field)); + } else if (field[0][0] === field[1][1] && field[1][1] === field[2][2]) { + return field[0][0]; + } else if (field[2][0] === field[1][1] && field[1][1] === field[0][2]) { + return field[2][0]; + } + + return winner; +} +function check(field) { + + for (let i = 0; i < 3; i++) { + if (line(field[i]) !== 'draw') { + return line(field[i]); + } + } + + return 'draw'; +} +function line(field) { + if (field[0] === field[1] && field[1] === field[2]) { + return field[0]; + } + + return 'draw'; } module.exports = { From 5b89fdb9725594133d8258eee97c0be61abc79a2 Mon Sep 17 00:00:00 2001 From: ainail Date: Fri, 19 Oct 2018 00:41:14 +0500 Subject: [PATCH 2/6] first try --- .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ .idea/javascript-task-1.iml | 12 +++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 ++++++ index.js | 1 + package-lock.json | 22 ++++++++++++++++++++ package.json | 3 ++- warmup.spec.js | 1 + 9 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/javascript-task-1.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..c6cc8c819 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/javascript-task-1.iml b/.idea/javascript-task-1.iml new file mode 100644 index 000000000..24643cc37 --- /dev/null +++ b/.idea/javascript-task-1.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..28a804d89 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..e4430f417 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/index.js b/index.js index f4af1b126..9a20df1d6 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +/* eslint-disable linebreak-style */ 'use strict'; const { diff --git a/package-lock.json b/package-lock.json index 494068cdb..4f74ad512 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,6 +79,11 @@ "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" }, + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -280,6 +285,15 @@ "rimraf": "^2.2.8" } }, + "dezalgo": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz", + "integrity": "sha1-f3Qt4Gb8dIvI24IFad3c5Jvw1FY=", + "requires": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -917,6 +931,14 @@ "is-promise": "^2.1.0" } }, + "run-auto": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/run-auto/-/run-auto-2.0.3.tgz", + "integrity": "sha512-kmEkpcJFly4+IWOG9BvwroclzdYUKFSoi92h1FVK41zat+38epu8xjqBDz9eC0sWbPnB3ONYDbtTMnQeNdYhAw==", + "requires": { + "dezalgo": "^1.0.1" + } + }, "rx-lite": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", diff --git a/package.json b/package.json index 1b748943e..976c54ce9 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dependencies": { "eslint": "4.8.0", "eslint-config-hrundel": "1.3.0", - "mocha": "5.2.0" + "mocha": "5.2.0", + "run-auto": "2.0.3" } } diff --git a/warmup.spec.js b/warmup.spec.js index 1835c49be..d9e5d6d21 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -1,3 +1,4 @@ +/* eslint-disable linebreak-style */ /* eslint-env mocha */ 'use strict'; From 15d6a83122411b139052607e9d2ebc7abfe9d747 Mon Sep 17 00:00:00 2001 From: ainail Date: Fri, 19 Oct 2018 19:48:25 +0500 Subject: [PATCH 3/6] first try --- warmup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/warmup.js b/warmup.js index 36f506f5a..e8394efb3 100644 --- a/warmup.js +++ b/warmup.js @@ -24,14 +24,14 @@ 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 < 1) { + if (year < 0) { throw new RangeError(); } - return Math.trunc(year / 100) + 1; + return Math.ceil(year / 100); } /** @@ -110,7 +110,7 @@ function matrixProblem(matrix) { * @returns {String} Число n в системе счисления targetNs */ function numberSystemProblem(n, targetNs) { - if (typeof(n) !== 'number' || typeof(targetNs) !== 'number') { + if (!Number.isInteger(targetNs) || typeof(targetNs) !== 'number' || typeof(n) !== 'number') { throw new TypeError(); } if (targetNs < 2 || targetNs > 36) { From a9d9451fbe9a648d4c3b8803bbc2652bdc45936f Mon Sep 17 00:00:00 2001 From: ainail Date: Mon, 22 Oct 2018 14:57:16 +0500 Subject: [PATCH 4/6] lal --- .idea/workspace.xml | 377 ++++++++++++++++++++++++++++++++++++++++++++ warmup.js | 18 ++- 2 files changed, 391 insertions(+), 4 deletions(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..4013298bc --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,377 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + +