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/.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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1539790423746
+
+
+ 1539790423746
+
+
+
+
+
+
+
+
+ 1539891276934
+
+
+
+ 1539891276934
+
+
+ 1539960505614
+
+
+
+ 1539960505614
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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.js b/warmup.js
index eefda9891..88fba8247 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' || !Number.isInteger((year))) {
+ throw new TypeError();
+ }
+ if (year < 0) {
+ throw new RangeError();
+ }
+
+ return Math.ceil(year / 100);
}
/**
@@ -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,49 @@ 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;
+}
+
+function compRed(matrix, n) {
+ if (!Array.isArray((matrix)) || matrix.length !== n) {
+ throw new TypeError();
+ }
}
-/**
- * Транспонирует матрицу
- * @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++) {
+ compRed(matrix[i], n);
+ ans[i] = [];
+ for (let j = 0; j < m; j++) {
+ ans[i][j] = matrix[j][i];
+ }
+ }
+
+ return ans;
}
/**
@@ -63,7 +117,14 @@ function matrixProblem(matrix) {
* @returns {String} Число n в системе счисления targetNs
*/
function numberSystemProblem(n, targetNs) {
- // Ваше решение
+ if (!Number.isInteger(targetNs) || typeof(targetNs) !== 'number' || typeof(n) !== 'number') {
+ throw new TypeError();
+ }
+ if (targetNs > 36 || targetNs < 2) {
+ throw new RangeError();
+ }
+
+ return parseFloat(n).toString(targetNs);
}
/**
@@ -72,7 +133,13 @@ function numberSystemProblem(n, targetNs) {
* @returns {Boolean} Если соответствует формату, то true, а иначе false
*/
function phoneProblem(phoneNumber) {
- // Ваше решение
+ if (typeof(phoneNumber) !== 'string') {
+ throw new TypeError();
+ }
+
+ const expression = new RegExp(/^8-800-[0-9]{3}-[0-9]{2}-[0-9]{2}$/g);
+
+ return expression.test(phoneNumber);
}
/**
@@ -82,7 +149,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; 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 +174,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 = {
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';