From 9b5985ece153c71b3d435927fcb718ae6f52e40e Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Mon, 15 Oct 2018 21:41:20 +0500 Subject: [PATCH 01/24] 123 --- .gitignore | 1 + .idea/codeStyles/Project.xml | 21 ++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/javascript-task-1.iml | 12 + .idea/jsLibraryMappings.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 315 +++++++++++++++++++ warmup.js | 168 +++++++++- 11 files changed, 545 insertions(+), 9 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/javascript-task-1.iml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 552f22184..6896da6d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ *.log +.idea diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 000000000..6a3d3c7a7 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,21 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 000000000..79ee123c2 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file 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/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 000000000..d23208fbb --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ 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..098f897de --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + true + true + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1539191367618 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/warmup.js b/warmup.js index eefda9891..744830a91 100644 --- a/warmup.js +++ b/warmup.js @@ -8,7 +8,11 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { - // Ваше решение + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } + + throw new TypeError(); } /** @@ -19,7 +23,15 @@ 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; } /** @@ -30,7 +42,19 @@ function centuryByYearProblem(year) { * @returns {String} Цвет в формате RGB, например, '(255, 255, 255)' */ function colorsProblem(hexColor) { - // Ваше решение + if (typeof hexColor !== 'string') { + throw new TypeError(); + } + + if (hexColor.length > 7) { + throw new RangeError(); + } + + const red = parseInt(hexColor.substr(1, 2), 16); + const green = parseInt(hexColor.substr(3, 2), 16); + const blue = parseInt(hexColor.substr(5, 2), 16); + + return `(${red}, ${green}, ${blue})`; } /** @@ -41,7 +65,29 @@ function colorsProblem(hexColor) { * @returns {Number} Число Фибоначчи, находящееся на n-ой позиции */ function fibonacciProblem(n) { - // Ваше решение + if (typeof n !== 'number') { + throw new TypeError(); + } + + if (n < 0) { + throw new RangeError(); + } + + if (n - Math.trunc(n) !== 0) { + throw new RangeError(); + } + + let n1 = 0; + let n2 = 1; + + for (let i = 1; i <= n - 1; i++) { + let n11 = n1; + n1 = n2; + n2 = n11 + n2; + } + + return n2; + } /** @@ -51,7 +97,26 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - // Ваше решение + if (matrix.length === 0) { + return []; + } + + if (!Array.isArray(matrix[0])) { + throw new TypeError(); + } + + let matrixResult = []; + + for (let x = 0; x < matrix.length; x++) { + let row = []; + for (let y = 0; y < matrix[x].length; y++) { + row.push(matrix[y][x]); + } + + matrixResult.push(row); + } + + return matrixResult; } /** @@ -62,8 +127,41 @@ function matrixProblem(matrix) { * @throws {RangeError} Когда система счисления выходит за пределы значений [2, 36] * @returns {String} Число n в системе счисления targetNs */ +// eslint-disable-next-line function numberSystemProblem(n, targetNs) { - // Ваше решение + if (typeof n !== 'number') { + throw new TypeError(); + } + + if (typeof targetNs !== 'number') { + throw new TypeError(); + } + + if (targetNs < 2 || targetNs > 36) { + throw new RangeError(); + } + + const abc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'Q', + 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; + + let result = ''; + + while (n >= targetNs) { + const ost = n % targetNs; + result = result + abc[ost]; + n = (n - ost) / targetNs; + } + + if (n !== 0) { + result += abc[n]; + } + + result = result.split('') + .reverse() + .join(''); + + return result; } /** @@ -72,7 +170,7 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { - // Ваше решение + return /8-800-\d\d\d-\d\d-\d\d/.test(phoneNumber); } /** @@ -82,7 +180,13 @@ function phoneProblem(phoneNumber) { * @returns {Number} Количество улыбающихся смайликов в строке */ function smilesProblem(text) { - // Ваше решение + const matchResult = text.match(/(:-\))/g); + + if (matchResult) { + return matchResult.length; + } + + return 0; } /** @@ -91,8 +195,54 @@ function smilesProblem(text) { * @param {(('x' | 'o')[])[]} field Игровое поле 3x3 завершённой игры * @returns {'x' | 'o' | 'draw'} Результат игры */ +// eslint-disable-next-line function ticTacToeProblem(field) { - // Ваше решение + + for (let i = 1; i <= 2; i++) { + if (field[0].join('') === 'xxx') { + return 'x'; + } + if (field[0].join('') === 'ooo') { + return 'o'; + } + if (field[1].join('') === 'xxx') { + return 'x'; + } + + if (field[1].join('') === 'ooo') { + return 'o'; + } + + if (field[2].join('') === 'xxx') { + return 'x'; + } + + if (field[2].join('') === 'ooo') { + return 'o'; + } + + field = matrixProblem(field); + } + + for (let i = 1; i <= 2; i++) { + let result = ''; + + for (let j = 0; j <= 2; j++) { + result = result + field[j][j]; + } + + if (result === 'xxx') { + return 'x'; + } + + if (result === 'ooo') { + return 'o'; + } + field = matrixProblem(field); + } + + return 'draw'; + } module.exports = { From 98b06cea807e21fff1de1c4ac5f341e818c0f4b4 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:15:55 +0500 Subject: [PATCH 02/24] 123 --- .idea/workspace.xml | 185 ++++++++++++++++++++++++++++++++------------ warmup.js | 18 ++--- warmup.spec.js | 24 ++++++ 3 files changed, 167 insertions(+), 60 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 098f897de..57c07b6d4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,17 +2,9 @@ - - - - - - - - - - + + @@ -28,9 +20,10 @@ + - + @@ -49,18 +42,18 @@ - + - + - + @@ -72,25 +65,25 @@ - + - + - - + + - + - - + + @@ -103,8 +96,8 @@ - - + + @@ -128,8 +121,9 @@ @@ -156,10 +150,8 @@ - @@ -216,6 +208,79 @@ + + + project + + $PROJECT_DIR$ + true + bdd + + TEST + $PROJECT_DIR$/warmup.spec.js + + + + + + + + project + + $PROJECT_DIR$ + true + bdd + + SUITE + $PROJECT_DIR$/warmup.spec.js + + + + + + + project + + $PROJECT_DIR$ + true + bdd + + SUITE + $PROJECT_DIR$/warmup.spec.js + + + + + + + project + + $PROJECT_DIR$ + true + bdd + + SUITE + $PROJECT_DIR$/warmup.spec.js + + + + + + + + + + + + + + + + + + + + @@ -227,12 +292,36 @@ + + + + + + + + + + + + + + + + + + + + + + + - @@ -247,13 +336,13 @@ - + - + @@ -261,7 +350,7 @@ - + @@ -274,40 +363,38 @@ - - - + - + - - - - - + + - + - + - - + + + + + - + - - + + diff --git a/warmup.js b/warmup.js index 744830a91..c979b8345 100644 --- a/warmup.js +++ b/warmup.js @@ -69,11 +69,7 @@ function fibonacciProblem(n) { throw new TypeError(); } - if (n < 0) { - throw new RangeError(); - } - - if (n - Math.trunc(n) !== 0) { + if (n < 1 || Math.trunc(n) !== n) { throw new RangeError(); } @@ -97,17 +93,17 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - if (matrix.length === 0) { - return []; - } - - if (!Array.isArray(matrix[0])) { + if (!Array.isArray(matrix)) { throw new TypeError(); } let matrixResult = []; for (let x = 0; x < matrix.length; x++) { + if (!Array.isArray(matrix[x])) { + throw new TypeError(); + } + let row = []; for (let y = 0; y < matrix[x].length; y++) { row.push(matrix[y][x]); @@ -153,7 +149,7 @@ function numberSystemProblem(n, targetNs) { n = (n - ost) / targetNs; } - if (n !== 0) { + if (n !== 0 || result.length === 0) { result += abc[n]; } diff --git a/warmup.spec.js b/warmup.spec.js index 1835c49be..45e7917d2 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -25,6 +25,10 @@ describe('Century by year problem', () => { it('Должна вернуть `21`', () => { assert.strictEqual(centuryByYearProblem(2018), 21); }); + + it('Должен вернуть 1', () => { + assert.strictEqual(centuryByYearProblem(1), 1); + }); }); describe('Colors problem', function () { @@ -37,6 +41,14 @@ describe('Fibonacci problem', () => { it('Для n=1 должна вернуть `1`', () => { assert.strictEqual(fibonacciProblem(1), 1); }); + + it('Для n=2 должна вернуть `1`', () => { + assert.strictEqual(fibonacciProblem(2), 1); + }); + + it('Для n=3 должна вернуть `2`', () => { + assert.strictEqual(fibonacciProblem(3), 2); + }); }); describe('Matrix problem', () => { @@ -58,6 +70,10 @@ describe('Number System Problem', () => { it('Должна вернуть "101"', () => { assert.strictEqual(numberSystemProblem(5, 2), '101'); }); + + it('Должна вернуть "0"', () => { + assert.strictEqual(numberSystemProblem(0, 2), '0'); + }); }); describe('Phone problem', () => { @@ -70,6 +86,14 @@ describe('Smiles problem', () => { it('Должна вернуть `1`', () => { assert.strictEqual(smilesProblem(':-)'), 1); }); + + it('Должна вернуть `3`', () => { + assert.strictEqual(smilesProblem(':-))) lskdjflskdfj :-)fsldkjflsd :-)'), 3); + }); + + it('Должна вернуть `0`', () => { + assert.strictEqual(smilesProblem('ljdslkfjsdlf sdfj lsdfj'), 0); + }); }); describe('Tic-tac-toe problem', () => { From e24f69af2bfa0f6e131d8e5200944ab31039fadd Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:31:55 +0500 Subject: [PATCH 03/24] hhuh --- .idea/workspace.xml | 24 +++++++++++------------- warmup.js | 5 +++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 57c07b6d4..d1f573f4b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,7 @@ - - @@ -48,12 +46,12 @@ - + - + @@ -73,8 +71,8 @@ - - + + @@ -122,8 +120,8 @@ @@ -293,7 +291,7 @@ 1539191367618 - + @@ -321,7 +319,7 @@ - @@ -342,7 +340,7 @@ - + @@ -350,7 +348,7 @@ - + @@ -393,8 +391,8 @@ - - + + diff --git a/warmup.js b/warmup.js index c979b8345..ed4f9b6e8 100644 --- a/warmup.js +++ b/warmup.js @@ -8,6 +8,10 @@ * @returns {Number} Сумма аргументов */ function abProblem(a, b) { + if (Math.trunc(a) !== a || Math.trunc(b) !== b) { + throw new TypeError(); + } + if (typeof a === 'number' && typeof b === 'number') { return a + b; } @@ -23,6 +27,7 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { + if (typeof year !== 'number') { throw new TypeError(); } From 9664d0af42aa527978549b92752009459cfa5948 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:37:04 +0500 Subject: [PATCH 04/24] hhuh --- .idea/workspace.xml | 53 ++++++++++++++++++++++++++++++++------------- warmup.js | 3 +++ warmup.spec.js | 8 +++++++ 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d1f573f4b..1fb58cf91 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + @@ -46,12 +47,12 @@ - + - + @@ -71,8 +72,8 @@ - - + + @@ -94,8 +95,8 @@ - - + + @@ -206,7 +207,21 @@ - + + + project + + $PROJECT_DIR$ + true + bdd + + SUITE + $PROJECT_DIR$/warmup.spec.js + + + + + project @@ -269,9 +284,11 @@ + + @@ -291,7 +308,7 @@ 1539191367618 - + @@ -317,9 +334,15 @@ + + + + + + - @@ -340,7 +363,7 @@ - + @@ -348,7 +371,7 @@ - + @@ -381,8 +404,8 @@ - - + + @@ -391,8 +414,8 @@ - - + + diff --git a/warmup.js b/warmup.js index ed4f9b6e8..18fcc7d6d 100644 --- a/warmup.js +++ b/warmup.js @@ -27,6 +27,9 @@ function abProblem(a, b) { * @returns {Number} Век, полученный из года */ function centuryByYearProblem(year) { + if (Math.trunc(year) !== year) { + throw new TypeError(); + } if (typeof year !== 'number') { throw new TypeError(); diff --git a/warmup.spec.js b/warmup.spec.js index 45e7917d2..c00b2f4af 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -29,6 +29,14 @@ describe('Century by year problem', () => { it('Должен вернуть 1', () => { assert.strictEqual(centuryByYearProblem(1), 1); }); + + it('Должен вернуть 1', () => { + assert.strictEqual(centuryByYearProblem(0), 1); + }); + + it('Должен вернуть 2', () => { + assert.strictEqual(centuryByYearProblem(100), 2); + }); }); describe('Colors problem', function () { From cf5183d3dd6a7c125a960d2c4c365aa09b0b6911 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:41:17 +0500 Subject: [PATCH 05/24] 123 --- .idea/workspace.xml | 21 ++++++++++----------- warmup.js | 6 +++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1fb58cf91..3e2418902 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,6 @@ - @@ -47,12 +46,12 @@ - + - + @@ -72,8 +71,8 @@ - - + + @@ -308,7 +307,7 @@ 1539191367618 - + @@ -342,7 +341,7 @@ - @@ -363,7 +362,7 @@ - + @@ -371,7 +370,7 @@ - + @@ -414,8 +413,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 18fcc7d6d..7c8712bf2 100644 --- a/warmup.js +++ b/warmup.js @@ -54,7 +54,11 @@ function colorsProblem(hexColor) { throw new TypeError(); } - if (hexColor.length > 7) { + if (hexColor.length !== 7) { + throw new RangeError(); + } + + if (!/#[a-f|A-F|0-9]+/.test(hexColor)) { throw new RangeError(); } From ff17b8d467e6c97bcf031dad23d53c4b4afbbad7 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:55:21 +0500 Subject: [PATCH 06/24] 324' --- .idea/workspace.xml | 51 ++++++++++++++++++++++++--------------------- warmup.js | 8 +++++-- warmup.spec.js | 8 +++++++ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3e2418902..502cddd5d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + @@ -46,12 +47,12 @@ - + - + @@ -71,8 +72,8 @@ - - + + @@ -94,8 +95,8 @@ - - + + @@ -206,7 +207,7 @@ - + project @@ -221,18 +222,17 @@ - + project $PROJECT_DIR$ true bdd - TEST + SUITE $PROJECT_DIR$/warmup.spec.js - - + @@ -279,19 +279,19 @@ - + + - @@ -307,14 +307,11 @@ 1539191367618 - + - - - @@ -339,9 +336,15 @@ + + + + + + - @@ -362,7 +365,7 @@ - + @@ -370,7 +373,7 @@ - + @@ -403,8 +406,8 @@ - - + + @@ -413,8 +416,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 7c8712bf2..e611589f9 100644 --- a/warmup.js +++ b/warmup.js @@ -109,15 +109,19 @@ function matrixProblem(matrix) { throw new TypeError(); } + if (matrix.length === 0) { + return []; + } + let matrixResult = []; - for (let x = 0; x < matrix.length; x++) { + for (let x = 0; x < matrix[x].length; x++) { if (!Array.isArray(matrix[x])) { throw new TypeError(); } let row = []; - for (let y = 0; y < matrix[x].length; y++) { + for (let y = 0; y < matrix.length; y++) { row.push(matrix[y][x]); } diff --git a/warmup.spec.js b/warmup.spec.js index c00b2f4af..59bd47e91 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -43,6 +43,14 @@ describe('Colors problem', function () { it('Должна вернуть (255, 255, 255)', function () { assert.strictEqual(colorsProblem('#FFFFFF'), '(255, 255, 255)'); }); + + it('Ошибка', function () { + try { + colorsProblem('#ABCDEZ'); + } catch (e) { + assert.ok(); + } + }); }); describe('Fibonacci problem', () => { From 382701ffa2fcb392cc8291cefd1bcb3600ebae6f Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 20:56:29 +0500 Subject: [PATCH 07/24] 324' --- .idea/workspace.xml | 35 +++++++++++++++++------------------ warmup.js | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 502cddd5d..747a05a70 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,6 @@ - @@ -47,12 +46,12 @@ - + - + @@ -72,8 +71,8 @@ - - + + @@ -95,8 +94,8 @@ - - + + @@ -307,7 +306,7 @@ 1539191367618 - + @@ -344,7 +343,7 @@ - @@ -365,7 +364,7 @@ - + @@ -373,7 +372,7 @@ - + @@ -387,9 +386,6 @@ - - - @@ -404,10 +400,13 @@ + + + - - + + @@ -416,8 +415,8 @@ - - + + diff --git a/warmup.js b/warmup.js index e611589f9..22b194a1b 100644 --- a/warmup.js +++ b/warmup.js @@ -115,7 +115,7 @@ function matrixProblem(matrix) { let matrixResult = []; - for (let x = 0; x < matrix[x].length; x++) { + for (let x = 0; x < matrix[0].length; x++) { if (!Array.isArray(matrix[x])) { throw new TypeError(); } From 0f3e6d3a93ca17bedbd8c9161f767dbd6e5f0d69 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Wed, 17 Oct 2018 21:29:19 +0500 Subject: [PATCH 08/24] fhdsk' git push origin git add -A git commit -m fdjkhsjkf git push origin ' git push origin --- .idea/workspace.xml | 64 +++++++++++++++++++++++---------------------- warmup.js | 4 +-- warmup.spec.js | 20 ++++++++++++++ 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 747a05a70..127b28d38 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,9 @@ + + @@ -46,12 +48,12 @@ - + - + @@ -71,8 +73,8 @@ - - + + @@ -94,8 +96,8 @@ - - + + @@ -206,7 +208,7 @@ - + project @@ -235,7 +237,7 @@ - + project $PROJECT_DIR$ @@ -245,11 +247,11 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + - + project $PROJECT_DIR$ @@ -259,11 +261,11 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + - + project $PROJECT_DIR$ @@ -273,24 +275,24 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + - + + + - - @@ -306,20 +308,11 @@ 1539191367618 - + - - - - - - - - - @@ -341,9 +334,18 @@ + + + + + + + + + - @@ -405,8 +407,8 @@ - - + + @@ -415,8 +417,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 22b194a1b..4dc740fd6 100644 --- a/warmup.js +++ b/warmup.js @@ -173,7 +173,7 @@ function numberSystemProblem(n, targetNs) { .reverse() .join(''); - return result; + return result.toLocaleLowerCase(); } /** @@ -240,7 +240,7 @@ function ticTacToeProblem(field) { let result = ''; for (let j = 0; j <= 2; j++) { - result = result + field[j][j]; + result += field[j][j]; } if (result === 'xxx') { diff --git a/warmup.spec.js b/warmup.spec.js index 59bd47e91..2037876b2 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -90,6 +90,10 @@ describe('Number System Problem', () => { it('Должна вернуть "0"', () => { assert.strictEqual(numberSystemProblem(0, 2), '0'); }); + + it('Должна вернуть "5"', () => { + assert.strictEqual(numberSystemProblem(5, 16), '5'); + }); }); describe('Phone problem', () => { @@ -120,4 +124,20 @@ describe('Tic-tac-toe problem', () => { ['o', 'x', 'o'] ]), 'x'); }); + + it('Должна вернуть "o"', () => { + assert.strictEqual(ticTacToeProblem([ + ['o', 'x', 'x'], + ['o', 'o', 'x'], + ['o', 'x', 'o'] + ]), 'o'); + }); + + it('Должна вернуть "draw"', () => { + assert.strictEqual(ticTacToeProblem([ + ['x', 'o', 'x'], + ['o', 'o', 'x'], + ['o', 'x', 'o'] + ]), 'draw'); + }); }); From 77bca62faf97b46ecee8961dabe5445206b3730a Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Thu, 18 Oct 2018 23:28:07 +0500 Subject: [PATCH 09/24] hdfjkssdf --- .idea/workspace.xml | 57 +++++++++++++++++++++++---------------------- warmup.js | 4 ++++ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 127b28d38..76e65e411 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,6 @@ - @@ -21,9 +20,10 @@ + - + @@ -42,18 +42,18 @@ - + - + - + @@ -64,7 +64,7 @@ - + @@ -73,8 +73,8 @@ - - + + @@ -96,7 +96,7 @@ - + @@ -159,23 +159,23 @@ - - + + - - + + @@ -308,7 +308,8 @@ 1539191367618 - + + @@ -345,7 +346,7 @@ - @@ -388,17 +389,17 @@ - + - - + + - + - - + + @@ -407,7 +408,7 @@ - + @@ -417,8 +418,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 4dc740fd6..0de74e2e6 100644 --- a/warmup.js +++ b/warmup.js @@ -182,6 +182,10 @@ function numberSystemProblem(n, targetNs) { * @returns {Boolean} Если соответствует формату, то true, а иначе false */ function phoneProblem(phoneNumber) { + if (typeof phoneNumber !== 'string') { + throw new TypeError(); + } + return /8-800-\d\d\d-\d\d-\d\d/.test(phoneNumber); } From 0991f39b352df1ba1187e8a1061986e7cc4c094f Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Thu, 18 Oct 2018 23:50:41 +0500 Subject: [PATCH 10/24] hdfjkssfdsdsf --- .idea/workspace.xml | 154 ++++++++++++++++++++++++++++---------------- warmup.js | 8 ++- warmup.spec.js | 6 +- 3 files changed, 112 insertions(+), 56 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 76e65e411..84bcb0eb5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,8 @@ - + @@ -28,15 +28,20 @@ + + + + + - + @@ -48,12 +53,12 @@ - + - + @@ -61,20 +66,11 @@ - - - - - - - - - - - + + @@ -88,16 +84,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -122,8 +148,8 @@ @@ -208,36 +234,38 @@ - - + + project $PROJECT_DIR$ true bdd - SUITE + TEST $PROJECT_DIR$/warmup.spec.js + - + project $PROJECT_DIR$ true bdd - SUITE + TEST $PROJECT_DIR$/warmup.spec.js - + + - + project $PROJECT_DIR$ @@ -247,11 +275,11 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + - + project $PROJECT_DIR$ @@ -261,7 +289,7 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + @@ -281,18 +309,18 @@ - - + + + + - - @@ -309,23 +337,11 @@ - + - - - - - - - - - - - - @@ -344,9 +360,21 @@ + + + + + + + + + + + + - @@ -361,13 +389,13 @@ - + - + @@ -375,7 +403,7 @@ - + @@ -396,6 +424,12 @@ + + + + + + @@ -403,13 +437,25 @@ - + + + + + + + + + + + + + - - + + @@ -418,8 +464,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 0de74e2e6..1838aa94e 100644 --- a/warmup.js +++ b/warmup.js @@ -39,7 +39,13 @@ function centuryByYearProblem(year) { throw new RangeError(); } - return Math.trunc(year / 100) + 1; + if (year % 100 !== 0) { + return Math.trunc(year / 100) + 1; + } + + if (year % 100 === 0) { + return year / 100; + } } /** diff --git a/warmup.spec.js b/warmup.spec.js index 2037876b2..c43b73996 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -35,8 +35,12 @@ describe('Century by year problem', () => { }); it('Должен вернуть 2', () => { - assert.strictEqual(centuryByYearProblem(100), 2); + assert.strictEqual(centuryByYearProblem(200), 2); }); + it('Должна вернуть `10`', () => { + assert.strictEqual(centuryByYearProblem(1000), 11); + }); + }); describe('Colors problem', function () { From a619afeca221ce4dee1e1e51234581e41e840945 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Thu, 18 Oct 2018 23:57:50 +0500 Subject: [PATCH 11/24] hdfjksfsfsfdsfe --- .idea/workspace.xml | 41 ++++++++++++++++++++--------------------- warmup.spec.js | 6 +----- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84bcb0eb5..3767e7764 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - @@ -53,12 +52,12 @@ - + - + @@ -66,10 +65,10 @@ - + - + @@ -119,11 +118,11 @@ - + - - + + @@ -337,7 +336,7 @@ - + @@ -374,7 +373,7 @@ - @@ -395,7 +394,7 @@ - + @@ -403,7 +402,7 @@ - + @@ -452,20 +451,20 @@ - + - - - - - + + - + - - + + + + + diff --git a/warmup.spec.js b/warmup.spec.js index c43b73996..5e4a99ca7 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -30,15 +30,11 @@ describe('Century by year problem', () => { assert.strictEqual(centuryByYearProblem(1), 1); }); - it('Должен вернуть 1', () => { - assert.strictEqual(centuryByYearProblem(0), 1); - }); - it('Должен вернуть 2', () => { assert.strictEqual(centuryByYearProblem(200), 2); }); it('Должна вернуть `10`', () => { - assert.strictEqual(centuryByYearProblem(1000), 11); + assert.strictEqual(centuryByYearProblem(1000), 10); }); }); From 3d0f75c2eaeff35691fa17743265c77b0b63f717 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 00:00:19 +0500 Subject: [PATCH 12/24] hdf --- .idea/workspace.xml | 38 +++++++++++++++++++------------------- warmup.js | 4 ++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3767e7764..d7ba1c3ea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -52,12 +52,12 @@ - + - + @@ -65,11 +65,11 @@ - + - - + + @@ -118,10 +118,10 @@ - + - + @@ -147,8 +147,8 @@ @@ -336,7 +336,7 @@ - + @@ -373,7 +373,7 @@ - @@ -451,16 +451,9 @@ - - - - - - - - + @@ -468,5 +461,12 @@ + + + + + + + \ No newline at end of file diff --git a/warmup.js b/warmup.js index 1838aa94e..ed96baee8 100644 --- a/warmup.js +++ b/warmup.js @@ -39,6 +39,10 @@ function centuryByYearProblem(year) { throw new RangeError(); } + if (year === 0) { + return 0; + } + if (year % 100 !== 0) { return Math.trunc(year / 100) + 1; } From 304a45b012d3add2b1835b382e15126cd4aaeaf6 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 00:07:53 +0500 Subject: [PATCH 13/24] h --- .idea/workspace.xml | 20 ++++++++++---------- warmup.js | 6 +----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d7ba1c3ea..7c9c16d27 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -52,12 +52,12 @@ - + - + @@ -68,8 +68,8 @@ - - + + @@ -121,7 +121,7 @@ - + @@ -336,7 +336,7 @@ - + @@ -373,7 +373,7 @@ - @@ -453,7 +453,7 @@ - + @@ -463,8 +463,8 @@ - - + + diff --git a/warmup.js b/warmup.js index ed96baee8..29279673c 100644 --- a/warmup.js +++ b/warmup.js @@ -31,14 +31,10 @@ function centuryByYearProblem(year) { throw new TypeError(); } - if (typeof year !== 'number') { + if (typeof year !== 'number' && year < 0) { throw new TypeError(); } - if (year < 0) { - throw new RangeError(); - } - if (year === 0) { return 0; } From 4831c5cfd30b165468d38dc4456083dc3cbd8ba0 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 00:24:00 +0500 Subject: [PATCH 14/24] h --- .idea/workspace.xml | 21 +++++++++++---------- warmup.js | 16 +++++++++++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7c9c16d27..85cab1731 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,7 @@ + @@ -52,12 +53,12 @@ - + - + @@ -68,8 +69,8 @@ - - + + @@ -336,7 +337,7 @@ - + @@ -373,7 +374,7 @@ - @@ -388,7 +389,7 @@ - + @@ -402,7 +403,7 @@ - + @@ -463,8 +464,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 29279673c..ac1c3584b 100644 --- a/warmup.js +++ b/warmup.js @@ -31,12 +31,12 @@ function centuryByYearProblem(year) { throw new TypeError(); } - if (typeof year !== 'number' && year < 0) { + if (typeof year !== 'number') { throw new TypeError(); } - if (year === 0) { - return 0; + if (year < 0) { + throw new RangeError(); } if (year % 100 !== 0) { @@ -203,12 +203,18 @@ function phoneProblem(phoneNumber) { */ function smilesProblem(text) { const matchResult = text.match(/(:-\))/g); + const matchResult2 = text.match(/(\(-:)/g); + let result = 0; if (matchResult) { - return matchResult.length; + result += matchResult.length; + } + + if (matchResult2) { + result += matchResult2.length; } - return 0; + return result; } /** From 8c77e05873be5377f5617f1f28cb97daea8ac662 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 00:34:55 +0500 Subject: [PATCH 15/24] h --- .idea/workspace.xml | 17 ++++++++--------- warmup.js | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 85cab1731..259bcb53e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - @@ -53,12 +52,12 @@ - + - + @@ -69,8 +68,8 @@ - - + + @@ -337,7 +336,7 @@ - + @@ -374,7 +373,7 @@ - @@ -464,8 +463,8 @@ - - + + diff --git a/warmup.js b/warmup.js index ac1c3584b..3df6e01bd 100644 --- a/warmup.js +++ b/warmup.js @@ -160,7 +160,7 @@ function numberSystemProblem(n, targetNs) { } const abc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'Q', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; let result = ''; From e33c1dac09ddf741d794c943b3e25b0a61cc5e85 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 00:41:45 +0500 Subject: [PATCH 16/24] h --- .idea/workspace.xml | 16 ++++++++-------- warmup.js | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 259bcb53e..90eb16217 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -52,12 +52,12 @@ - + - + @@ -68,8 +68,8 @@ - - + + @@ -336,7 +336,7 @@ - + @@ -373,7 +373,7 @@ - @@ -463,8 +463,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 3df6e01bd..30a450b34 100644 --- a/warmup.js +++ b/warmup.js @@ -165,6 +165,9 @@ function numberSystemProblem(n, targetNs) { let result = ''; + if (n < 0) { + result = '-'; + } while (n >= targetNs) { const ost = n % targetNs; result = result + abc[ost]; From b25a9fbdd5f8192d29b64fa53065517841f18338 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 01:08:00 +0500 Subject: [PATCH 17/24] h --- .idea/workspace.xml | 41 +++++++++++++++++++++-------------------- warmup.js | 3 ++- warmup.spec.js | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 90eb16217..b8135256c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + @@ -52,12 +53,12 @@ - + - + @@ -65,11 +66,11 @@ - + - - + + @@ -118,11 +119,11 @@ - + - - + + @@ -147,8 +148,8 @@ @@ -336,7 +337,7 @@ - + @@ -373,7 +374,7 @@ - @@ -451,20 +452,20 @@ - + - - - - - + + - + - - + + + + + diff --git a/warmup.js b/warmup.js index 30a450b34..45da395bd 100644 --- a/warmup.js +++ b/warmup.js @@ -64,7 +64,7 @@ function colorsProblem(hexColor) { throw new RangeError(); } - if (!/#[a-f|A-F|0-9]+/.test(hexColor)) { + if (!/#[a-f|A-F|0-9]{6}/.test(hexColor)) { throw new RangeError(); } @@ -168,6 +168,7 @@ function numberSystemProblem(n, targetNs) { if (n < 0) { result = '-'; } + while (n >= targetNs) { const ost = n % targetNs; result = result + abc[ost]; diff --git a/warmup.spec.js b/warmup.spec.js index 5e4a99ca7..96ae12d50 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -48,7 +48,7 @@ describe('Colors problem', function () { try { colorsProblem('#ABCDEZ'); } catch (e) { - assert.ok(); + assert.ok('s'); } }); }); From 5f47b8de40b9cccec2737fdb8dffa177a7c00089 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 01:11:40 +0500 Subject: [PATCH 18/24] h --- .idea/workspace.xml | 37 ++++++++++++++++++------------------- warmup.js | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b8135256c..22d01a80b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,6 @@ - @@ -53,12 +52,12 @@ - + - + @@ -66,11 +65,11 @@ - + - - + + @@ -119,10 +118,10 @@ - + - + @@ -148,8 +147,8 @@ @@ -337,7 +336,7 @@ - + @@ -374,7 +373,7 @@ - @@ -452,16 +451,9 @@ - - - - - - - - + @@ -469,5 +461,12 @@ + + + + + + + \ No newline at end of file diff --git a/warmup.js b/warmup.js index 45da395bd..256ee51c9 100644 --- a/warmup.js +++ b/warmup.js @@ -196,7 +196,7 @@ function phoneProblem(phoneNumber) { throw new TypeError(); } - return /8-800-\d\d\d-\d\d-\d\d/.test(phoneNumber); + return /^8-800-\d\d\d-\d\d-\d\d$/.test(phoneNumber); } /** From 8a2cc1ce2e277d55546f92c2067030e95fc23a63 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 01:26:33 +0500 Subject: [PATCH 19/24] h --- .idea/workspace.xml | 54 +++++++++++++++++++++++---------------------- warmup.js | 4 ---- warmup.spec.js | 14 ++++++++++++ 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 22d01a80b..9adfd988e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + @@ -52,12 +53,12 @@ - + - + @@ -68,8 +69,8 @@ - - + + @@ -121,8 +122,8 @@ - - + + @@ -233,7 +234,7 @@ - + project @@ -264,17 +265,18 @@ - + project $PROJECT_DIR$ true bdd - SUITE + TEST $PROJECT_DIR$/warmup.spec.js - + + @@ -308,18 +310,18 @@ - + + - @@ -336,17 +338,11 @@ - + - - - - - - @@ -371,9 +367,15 @@ + + + + + + - @@ -394,7 +396,7 @@ - + @@ -402,7 +404,7 @@ - + @@ -453,8 +455,8 @@ - - + + @@ -463,8 +465,8 @@ - - + + diff --git a/warmup.js b/warmup.js index 256ee51c9..54774f71f 100644 --- a/warmup.js +++ b/warmup.js @@ -122,10 +122,6 @@ function matrixProblem(matrix) { let matrixResult = []; for (let x = 0; x < matrix[0].length; x++) { - if (!Array.isArray(matrix[x])) { - throw new TypeError(); - } - let row = []; for (let y = 0; y < matrix.length; y++) { row.push(matrix[y][x]); diff --git a/warmup.spec.js b/warmup.spec.js index 96ae12d50..26fb10ce4 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -80,6 +80,20 @@ describe('Matrix problem', () => { [3, 6, 9] ]); }); + + it('Должна транспонировать квадратную матрицу 3x3', () => { + assert.deepStrictEqual( + matrixProblem([ + [1, 2, 3, 4], + [4, 5, 6, 7], + [7, 8, 9, 10] + ]), [ + [1, 4, 7], + [2, 5, 8], + [3, 6, 9], + [4, 7, 10] + ]); + }); }); describe('Number System Problem', () => { From 7e6812403d445a4f0f2081e42970a7f9b37a1ae4 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 01:29:12 +0500 Subject: [PATCH 20/24] h --- .idea/workspace.xml | 45 ++++++++++++++++++++++----------------------- warmup.spec.js | 15 +++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9adfd988e..2b64da5f8 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - @@ -53,12 +52,12 @@ - + - + @@ -66,10 +65,10 @@ - + - + @@ -119,11 +118,11 @@ - + - - + + @@ -148,8 +147,8 @@ @@ -338,7 +337,7 @@ - + @@ -375,7 +374,7 @@ - @@ -390,13 +389,13 @@ - + - + @@ -404,7 +403,7 @@ - + @@ -453,20 +452,20 @@ - + - - - - - + + - + - - + + + + + diff --git a/warmup.spec.js b/warmup.spec.js index 26fb10ce4..309c32dcc 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -94,6 +94,21 @@ describe('Matrix problem', () => { [4, 7, 10] ]); }); + + it('Должна транспонировать квадратную матрицу 3x3', () => { + assert.deepStrictEqual( + matrixProblem([ + [1, 2, 3, 4, 5], + [4, 5, 6, 7, 8], + [7, 8, 9, 10, 11] + ]), [ + [1, 4, 7], + [2, 5, 8], + [3, 6, 9], + [4, 7, 10], + [5, 8, 11] + ]); + }); }); describe('Number System Problem', () => { From 668efb371b04cc7d40c2746d98a7b059965fde11 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 01:38:32 +0500 Subject: [PATCH 21/24] h --- .idea/workspace.xml | 42 +++++++++++++++++++++--------------------- warmup.js | 26 ++++++++++++++------------ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2b64da5f8..24b3bb671 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -52,12 +52,12 @@ - + - + @@ -65,11 +65,11 @@ - + - - + + @@ -118,11 +118,11 @@ - + - - + + @@ -147,8 +147,8 @@ @@ -337,7 +337,7 @@ - + @@ -374,7 +374,7 @@ - @@ -452,22 +452,22 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/warmup.js b/warmup.js index 54774f71f..31e84d68f 100644 --- a/warmup.js +++ b/warmup.js @@ -252,21 +252,23 @@ function ticTacToeProblem(field) { field = matrixProblem(field); } - for (let i = 1; i <= 2; i++) { - let result = ''; + const diag1 = field[0][0] + field[1][1] + field[2][2]; + const diag2 = field[0][2] + field[1][1] + field[2][0]; - for (let j = 0; j <= 2; j++) { - result += field[j][j]; - } + if (diag1 === 'xxx') { + return 'x'; + } - if (result === 'xxx') { - return 'x'; - } + if (diag1 === 'ooo') { + return 'o'; + } - if (result === 'ooo') { - return 'o'; - } - field = matrixProblem(field); + if (diag2 === 'xxx') { + return 'x'; + } + + if (diag2 === 'ooo') { + return 'o'; } return 'draw'; From 93b985d558797db5079b2104d6d4b911d25ce687 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 02:05:26 +0500 Subject: [PATCH 22/24] ggg --- .idea/workspace.xml | 78 +++++++++++++++++++++++---------------------- warmup.js | 30 +++++++++++++---- warmup.spec.js | 8 +++++ 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 24b3bb671..f6a9f1b15 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + @@ -52,12 +53,12 @@ - + - + @@ -65,11 +66,11 @@ - + - - + + @@ -118,11 +119,11 @@ - + - - + + @@ -147,8 +148,8 @@ @@ -233,7 +234,7 @@ - + project @@ -279,7 +280,7 @@ - + project $PROJECT_DIR$ @@ -289,38 +290,39 @@ SUITE $PROJECT_DIR$/warmup.spec.js - + - + project $PROJECT_DIR$ true bdd - SUITE + TEST $PROJECT_DIR$/warmup.spec.js + - + + - @@ -337,20 +339,11 @@ - + - - - - - - - - - @@ -372,9 +365,18 @@ + + + + + + + + + - @@ -389,7 +391,7 @@ - + @@ -403,7 +405,7 @@ - + @@ -452,20 +454,20 @@ - + - - - - - + + - + - - + + + + + diff --git a/warmup.js b/warmup.js index 31e84d68f..5a40c2515 100644 --- a/warmup.js +++ b/warmup.js @@ -141,6 +141,10 @@ function matrixProblem(matrix) { * @throws {RangeError} Когда система счисления выходит за пределы значений [2, 36] * @returns {String} Число n в системе счисления targetNs */ +const abc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', + 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; + // eslint-disable-next-line function numberSystemProblem(n, targetNs) { if (typeof n !== 'number') { @@ -155,16 +159,30 @@ function numberSystemProblem(n, targetNs) { throw new RangeError(); } - const abc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', - 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; - - let result = ''; + let [int, d] = n.toString().split('.'); + let result = toTargetNs(int, targetNs); + + if (d) { + result += '.'; + d = n - parseInt(int); + while (d !== 0) { + d = d * 2; + const [i] = d.toString().split('.'); + result += abc[i.toString()]; + d = d - i; + } + } if (n < 0) { - result = '-'; + result = '-' + result; } + return result.toLowerCase(); +} + +function toTargetNs(n, targetNs) { + let result = ''; + while (n >= targetNs) { const ost = n % targetNs; result = result + abc[ost]; diff --git a/warmup.spec.js b/warmup.spec.js index 309c32dcc..33be2fabd 100644 --- a/warmup.spec.js +++ b/warmup.spec.js @@ -169,4 +169,12 @@ describe('Tic-tac-toe problem', () => { ['o', 'x', 'o'] ]), 'draw'); }); + + it('Должна вернуть "x"', () => { + assert.strictEqual(ticTacToeProblem([ + ['o', 'o', 'x'], + ['o', 'x', 'x'], + ['x', 'o', 'o'] + ]), 'x'); + }); }); From c53f4a93ac7778cd64a43af5687b70b1fdfbcee6 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 14:15:00 +0500 Subject: [PATCH 23/24] ggg --- .idea/workspace.xml | 41 ++++++++++++++++++++--------------------- warmup.js | 4 ++++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f6a9f1b15..165c9213f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,6 @@ - @@ -53,12 +52,12 @@ - + - + @@ -66,11 +65,11 @@ - + - - + + @@ -119,10 +118,10 @@ - + - + @@ -148,8 +147,8 @@ @@ -339,7 +338,7 @@ - + @@ -376,7 +375,7 @@ - @@ -391,7 +390,7 @@ - + @@ -405,7 +404,7 @@ - + @@ -454,16 +453,9 @@ - - - - - - - - + @@ -471,5 +463,12 @@ + + + + + + + \ No newline at end of file diff --git a/warmup.js b/warmup.js index 5a40c2515..ce3f850ef 100644 --- a/warmup.js +++ b/warmup.js @@ -159,6 +159,10 @@ function numberSystemProblem(n, targetNs) { throw new RangeError(); } + if (n < 0) { + n = -n; + } + let [int, d] = n.toString().split('.'); let result = toTargetNs(int, targetNs); From 6913be6c50a3df9c3703b8b844ee35b6f6b855a9 Mon Sep 17 00:00:00 2001 From: sofelvpopel Date: Fri, 19 Oct 2018 14:31:22 +0500 Subject: [PATCH 24/24] ggg --- .idea/workspace.xml | 20 ++++++++++---------- warmup.js | 9 ++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 165c9213f..878dd7e6f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -52,12 +52,12 @@ - + - + @@ -68,8 +68,8 @@ - - + + @@ -338,7 +338,7 @@ - + @@ -375,7 +375,7 @@ - @@ -390,7 +390,7 @@ - + @@ -404,7 +404,7 @@ - + @@ -465,8 +465,8 @@ - - + + diff --git a/warmup.js b/warmup.js index ce3f850ef..d7e659086 100644 --- a/warmup.js +++ b/warmup.js @@ -111,14 +111,17 @@ function fibonacciProblem(n) { * @returns {(Any[])[]} Транспонированная матрица размера NxM */ function matrixProblem(matrix) { - if (!Array.isArray(matrix)) { - throw new TypeError(); - } if (matrix.length === 0) { return []; } + for (let i = 0; i < matrix.length; i++) { + if (!Array.isArray(matrix[i])) { + throw new TypeError(); + } + } + let matrixResult = []; for (let x = 0; x < matrix[0].length; x++) {