From 2e89c008558757397bc7d6fd53e0c17b3d0e6784 Mon Sep 17 00:00:00 2001 From: Aleksey <44395857+AlekseyPrusevich@users.noreply.github.com> Date: Tue, 30 Jun 2020 15:48:52 +0300 Subject: [PATCH 01/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79f9dff75..e629099ac 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ To start javascript assignments please follow the next steps: git commit -m "Update the links" git push origin master ``` -* Open https://github.com/rolling-scopes-school/js-assignments and test the build icon. Now it will run all tests and update status once you push changes to github. Keep this icon green! +* Open https://github.com/AlekseyPrusevich/js-assignments and test the build icon. Now it will run all tests and update status once you push changes to github. Keep this icon green! ### How to setup work environment From cf3bc940812d528ae0e687088bc2e1d814635ee7 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Tue, 30 Jun 2020 20:01:26 +0300 Subject: [PATCH 02/11] test1 5-13 --- package-lock.json | 154 +++++++++++++++++++++++++++++++++++++++ package.json | 6 +- task/01-strings-tasks.js | 64 ++++++++++++---- 3 files changed, 207 insertions(+), 17 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..9c3bb9263 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,154 @@ +{ + "name": "js-training", + "version": "0.9.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "commander": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", + "dev": true + }, + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "dev": true, + "requires": { + "ms": "0.7.1" + } + }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", + "dev": true + }, + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "dev": true, + "requires": { + "inherits": "2", + "minimatch": "0.3" + } + }, + "growl": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", + "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", + "dev": true + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.5.3.tgz", + "integrity": "sha1-FhvlvetJZ3HrmzV0UFC2IrWu/Fg=", + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.2.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.11", + "growl": "1.9.2", + "jade": "0.26.3", + "mkdirp": "0.5.1", + "supports-color": "1.2.0", + "to-iso-string": "0.0.2" + } + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "supports-color": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", + "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=", + "dev": true + }, + "to-iso-string": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/to-iso-string/-/to-iso-string-0.0.2.tgz", + "integrity": "sha1-TcGeZk38y+Jb2NtQiwDG2hWCVdE=", + "dev": true + } + } +} diff --git a/package.json b/package.json index 712b264fa..1f387c39b 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "devDependencies": { "mocha": "^2.3.4" }, - "repository" : { - "type" : "git", - "url" : "https://github.com/rolling-scopes-school/js-assignments.git" + "repository": { + "type": "git", + "url": "https://github.com/rolling-scopes-school/js-assignments.git" } } diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index e28054657..f991e44a3 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -12,7 +12,7 @@ /** * Returns the result of concatenation of two strings. * - * @param {string} value1 + * @param {string} value1 * @param {string} value2 * @return {string} * @@ -22,7 +22,9 @@ * '', 'bb' => 'bb' */ function concatenateStrings(value1, value2) { - throw new Error('Not implemented'); + return value1 + value2 + + //throw new Error('Not implemented'); } @@ -38,7 +40,9 @@ function concatenateStrings(value1, value2) { * '' => 0 */ function getStringLength(value) { - throw new Error('Not implemented'); + return value.length; + + //throw new Error('Not implemented'); } /** @@ -55,7 +59,9 @@ function getStringLength(value) { * 'Chuck','Norris' => 'Hello, Chuck Norris!' */ function getStringFromTemplate(firstName, lastName) { - throw new Error('Not implemented'); + return `Hello, ${firstName} ${lastName}!`; + + //throw new Error('Not implemented'); } /** @@ -69,7 +75,9 @@ function getStringFromTemplate(firstName, lastName) { * 'Hello, Chuck Norris!' => 'Chuck Norris' */ function extractNameFromTemplate(value) { - throw new Error('Not implemented'); + return value.replace('Hello, ', '').replace('!', ''); + + //throw new Error('Not implemented'); } @@ -84,7 +92,9 @@ function extractNameFromTemplate(value) { * 'cat' => 'c' */ function getFirstChar(value) { - throw new Error('Not implemented'); + return value.charAt(0); + + //throw new Error('Not implemented'); } /** @@ -99,7 +109,9 @@ function getFirstChar(value) { * '\tHello, World! ' => 'Hello, World!' */ function removeLeadingAndTrailingWhitespaces(value) { - throw new Error('Not implemented'); + return value.trim(); + + //throw new Error('Not implemented'); } /** @@ -114,7 +126,9 @@ function removeLeadingAndTrailingWhitespaces(value) { * 'cat', 3 => 'catcatcat' */ function repeatString(value, count) { - throw new Error('Not implemented'); + return value.repeat(count); + + //throw new Error('Not implemented'); } /** @@ -130,7 +144,9 @@ function repeatString(value, count) { * 'ABABAB','BA' => 'ABAB' */ function removeFirstOccurrences(str, value) { - throw new Error('Not implemented'); + return str.replace(value, ''); + + //throw new Error('Not implemented'); } /** @@ -145,7 +161,10 @@ function removeFirstOccurrences(str, value) { * '' => 'a' */ function unbracketTag(str) { - throw new Error('Not implemented'); + return str.replace(/[<>]/g, ''); + // return str.replace(str[0], '').replace(str[str.length-1], ''); + + //throw new Error('Not implemented'); } @@ -160,7 +179,9 @@ function unbracketTag(str) { * 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' */ function convertToUpperCase(str) { - throw new Error('Not implemented'); + return str.toUpperCase(str); + + //throw new Error('Not implemented'); } /** @@ -174,7 +195,9 @@ function convertToUpperCase(str) { * 'info@gmail.com' => ['info@gmail.com'] */ function extractEmails(str) { - throw new Error('Not implemented'); + return str.split(';'); + + //throw new Error('Not implemented'); } /** @@ -201,7 +224,11 @@ function extractEmails(str) { * */ function getRectangleString(width, height) { - throw new Error('Not implemented'); + return '┌' + '─'.repeat(width-2) + '┐' + '\n' + + ('│' + ' '.repeat(width-2) + '│\n').repeat(height-2) + + '└' + '─'.repeat(width-2) + '┘' + '\n'; + + //throw new Error('Not implemented'); } @@ -221,7 +248,13 @@ function getRectangleString(width, height) { * */ function encodeToRot13(str) { - throw new Error('Not implemented'); + + return str.replace(/[a-zA-Z]/g, function (c) { + return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26); + }); + + + //throw new Error('Not implemented'); } /** @@ -238,6 +271,9 @@ function encodeToRot13(str) { * isString(new String('test')) => true */ function isString(value) { + + //return value ? typeof value.valueOf() == 'string' : false; + throw new Error('Not implemented'); } From 85c73c8ca4f9de59d2c6b54312cf7fd376e4fec3 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Tue, 30 Jun 2020 21:03:15 +0300 Subject: [PATCH 03/11] test 2 1-4 --- task/01-strings-tasks.js | 9 +++++++-- task/02-numbers-tasks.js | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index f991e44a3..9e7734308 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -248,11 +248,16 @@ function getRectangleString(width, height) { * */ function encodeToRot13(str) { - +/* return str.replace(/[a-zA-Z]/g, function (c) { return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26); }); - +*/ + + function rot13(math) { + return String.fromCharCode((math <= "Z" ? 90 : 122) >= (math = math.charCodeAt(0) + 13) ? math : math - 26); + } + return str.replace(/[a-zA-Z]/g, rot13); //throw new Error('Not implemented'); } diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index c9ed20208..ed138ef5e 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -22,7 +22,9 @@ * 5, 5 => 25 */ function getRectangleArea(width, height) { - throw new Error('Not implemented'); + return width*height; + + //throw new Error('Not implemented'); } @@ -38,7 +40,9 @@ function getRectangleArea(width, height) { * 0 => 0 */ function getCicleCircumference(radius) { - throw new Error('Not implemented'); + return 2 * Math.PI * radius; + + //throw new Error('Not implemented'); } /** @@ -54,7 +58,10 @@ function getCicleCircumference(radius) { * -3, 3 => 0 */ function getAverage(value1, value2) { - throw new Error('Not implemented'); + + return value1 / 2 + value2 / 2; + + //throw new Error('Not implemented'); } /** @@ -73,6 +80,9 @@ function getAverage(value1, value2) { * (-5,0) (10,-10) => 18.027756377319946 */ function getDistanceBetweenPoints(x1, y1, x2, y2) { + + return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2); + throw new Error('Not implemented'); } From 640b13b36e6335649569b73624fec79c90bc4e72 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:09:58 +0300 Subject: [PATCH 04/11] test 3 1-4 --- task/01-strings-tasks.js | 6 +++--- task/02-numbers-tasks.js | 20 ++++++++++++++------ task/03-date-tasks.js | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index 9e7734308..655c2da38 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -252,14 +252,14 @@ function encodeToRot13(str) { return str.replace(/[a-zA-Z]/g, function (c) { return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26); }); -*/ + function rot13(math) { return String.fromCharCode((math <= "Z" ? 90 : 122) >= (math = math.charCodeAt(0) + 13) ? math : math - 26); } return str.replace(/[a-zA-Z]/g, rot13); - - //throw new Error('Not implemented'); +*/ + throw new Error('Not implemented'); } /** diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index ed138ef5e..29a184b99 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -58,7 +58,6 @@ function getCicleCircumference(radius) { * -3, 3 => 0 */ function getAverage(value1, value2) { - return value1 / 2 + value2 / 2; //throw new Error('Not implemented'); @@ -80,7 +79,6 @@ function getAverage(value1, value2) { * (-5,0) (10,-10) => 18.027756377319946 */ function getDistanceBetweenPoints(x1, y1, x2, y2) { - return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2); throw new Error('Not implemented'); @@ -99,6 +97,8 @@ function getDistanceBetweenPoints(x1, y1, x2, y2) { * 5*x = 0 => 0 */ function getLinearEquationRoot(a, b) { + return (-b) / a; + throw new Error('Not implemented'); } @@ -137,7 +137,9 @@ function getAngleBetweenVectors(x1, y1, x2, y2) { * 0 => 0 */ function getLastDigit(value) { - throw new Error('Not implemented'); + return value % 10; + + //throw new Error('Not implemented'); } @@ -153,7 +155,9 @@ function getLastDigit(value) { * '-525.5' => -525.5 */ function parseNumberFromString(value) { - throw new Error('Not implemented'); + return +value; + + //throw new Error('Not implemented'); } /** @@ -170,7 +174,9 @@ function parseNumberFromString(value) { * 1,2,3 => 3.741657386773941 */ function getParallelipidedDiagonal(a,b,c) { - throw new Error('Not implemented'); + return Math.sqrt(a ** 2 + b ** 2 + c ** 2); + + //throw new Error('Not implemented'); } /** @@ -191,7 +197,9 @@ function getParallelipidedDiagonal(a,b,c) { * 1678, 3 => 2000 */ function roundToPowerOfTen(num, pow) { - throw new Error('Not implemented'); + return Math.round(num / (10 ** pow)) * (10 ** pow); + + //throw new Error('Not implemented'); } /** diff --git a/task/03-date-tasks.js b/task/03-date-tasks.js index 83c6266bc..94c04b9f0 100644 --- a/task/03-date-tasks.js +++ b/task/03-date-tasks.js @@ -22,7 +22,9 @@ * 'Sun, 17 May 1998 03:00:00 GMT+01' => Date() */ function parseDataFromRfc2822(value) { - throw new Error('Not implemented'); + return Date.parse(value); + + //throw new Error('Not implemented'); } /** @@ -37,7 +39,9 @@ function parseDataFromRfc2822(value) { * '2016-01-19T08:07:37Z' => Date() */ function parseDataFromIso8601(value) { - throw new Error('Not implemented'); + return Date.parse(value); + + //throw new Error('Not implemented'); } @@ -56,7 +60,13 @@ function parseDataFromIso8601(value) { * Date(2015,1,1) => false */ function isLeapYear(date) { - throw new Error('Not implemented'); + let year = date.getFullYear(); + + return (+year % 4 != 0) ? false : + (+year % 100 != 0) ? true : + (+year % 400 != 0) ? false : true; + + //throw new Error('Not implemented'); } @@ -76,6 +86,24 @@ function isLeapYear(date) { * Date(2000,1,1,10,0,0), Date(2000,1,1,15,20,10,453) => "05:20:10.453" */ function timeSpanToString(startDate, endDate) { + + let dateDif = endDate - startDate; + let date = new Date(); + + /* + let hour = Math.floor(dateDif / 3.6e6); + let min = Math.floor((dateDif - hour * 3.6e6) / 6e4); + let sec = Math.floor((dateDif - hour * 3.6e6 - min * 6e4) / 1e3); + let ms = dateDif - hour * 3.6e6 - min * 6e4 - sec * 1e3; + + + date.setHours(Math.floor(dateDif / 3.6e6)); + date.setMinutes(Math.floor((dateDif % 3.6e6) / 6e4)); + date.setSeconds(Math.floor((dateDif % 3.6e6 % 6e4) / 1e3)); + date.setMilliseconds(dateDif % 3.6e6 % 6e4 % 1e3); + + return date.getHours(); + */ throw new Error('Not implemented'); } From 052a2107e9934092fb1e001db263feb4c96dfd94 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Wed, 1 Jul 2020 17:44:51 +0300 Subject: [PATCH 05/11] test 4 1-14 --- task/02-numbers-tasks.js | 4 +- task/04-arrays-tasks.js | 91 +++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index 29a184b99..dcd44e895 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -81,7 +81,7 @@ function getAverage(value1, value2) { function getDistanceBetweenPoints(x1, y1, x2, y2) { return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2); - throw new Error('Not implemented'); + //throw new Error('Not implemented'); } /** @@ -99,7 +99,7 @@ function getDistanceBetweenPoints(x1, y1, x2, y2) { function getLinearEquationRoot(a, b) { return (-b) / a; - throw new Error('Not implemented'); + //throw new Error('Not implemented'); } diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index ff3a4c019..792937218 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -1,5 +1,7 @@ 'use strict'; +const { parseDataFromRfc2822 } = require("./03-date-tasks"); + /********************************************************************************************* * * * Plese read the following tutorial before implementing tasks: * @@ -38,7 +40,10 @@ function findElement(arr, value) { * 5 => [ 1, 3, 5, 7, 9 ] */ function generateOdds(len) { - throw new Error('Not implemented'); + return new Array(len).fill(0).map(function(_, i) { + return 2 * i + 1; + }); + //throw new Error('Not implemented'); } @@ -54,7 +59,10 @@ function generateOdds(len) { * [] => [] */ function doubleArray(arr) { - throw new Error('Not implemented'); + + return [...arr, ...arr]; + + //throw new Error('Not implemented'); } @@ -70,7 +78,9 @@ function doubleArray(arr) { * [] => [] */ function getArrayOfPositives(arr) { - throw new Error('Not implemented'); + return arr.filter(arr => arr > 0); + + //throw new Error('Not implemented'); } /** @@ -85,7 +95,9 @@ function getArrayOfPositives(arr) { * [ 'cat, 'dog', 'raccon' ] => [ 'cat', 'dog', 'racoon' ] */ function getArrayOfStrings(arr) { - throw new Error('Not implemented'); + return arr.filter(arr => typeof arr == "string"); + + //throw new Error('Not implemented'); } /** @@ -102,7 +114,9 @@ function getArrayOfStrings(arr) { * [ false, 0, NaN, '', undefined ] => [ ] */ function removeFalsyValues(arr) { - throw new Error('Not implemented'); + return arr.filter(arr => Boolean(arr) == true ); + + //throw new Error('Not implemented'); } /** @@ -116,7 +130,9 @@ function removeFalsyValues(arr) { * [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ] => [ 'A', 'B', 'C', 'D', 'E', 'F', 'G' ] */ function getUpperCaseStrings(arr) { - throw new Error('Not implemented'); + return arr.map((element, _) => element.toUpperCase()); + + //throw new Error('Not implemented'); } @@ -131,7 +147,9 @@ function getUpperCaseStrings(arr) { * [ 'angular', 'react', 'ember' ] => [ 7, 5, 5 ] */ function getStringsLength(arr) { - throw new Error('Not implemented'); + return arr.map((element, _) => element.length); + + //throw new Error('Not implemented'); } /** @@ -146,7 +164,9 @@ function getStringsLength(arr) { * [ 1, 'b', 'c'], 0, 'x' => [ 'x', 1, 'b', 'c' ] */ function insertItem(arr, item, index) { - throw new Error('Not implemented'); + return arr.splice(index, 0, item); + + //throw new Error('Not implemented'); } /** @@ -160,7 +180,10 @@ function insertItem(arr, item, index) { * [ 'a', 'b', 'c', 'd'], 3 => [ 'a', 'b', 'c' ] */ function getHead(arr, n) { - throw new Error('Not implemented'); + let delered = arr.splice(n); + return arr; + + //throw new Error('Not implemented'); } @@ -175,7 +198,9 @@ function getHead(arr, n) { * [ 'a', 'b', 'c', 'd'], 3 => [ 'b', 'c', 'd' ] */ function getTail(arr, n) { - throw new Error('Not implemented'); + return arr.splice(-n); + + //throw new Error('Not implemented'); } @@ -215,7 +240,9 @@ function toCsvText(arr) { * [ 10, 100, -1 ] => [ 100, 10000, 1 ] */ function toArrayOfSquares(arr) { - throw new Error('Not implemented'); + return arr.map((element, _) => element ** 2); + + //throw new Error('Not implemented'); } @@ -234,7 +261,25 @@ function toArrayOfSquares(arr) { * [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] => [ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 ] */ function getMovingSum(arr) { - throw new Error('Not implemented'); + //return arr.map((element, index) => arr[index] == arr[0] ? arr[index] = arr[index] : arr[index] = arr[index] + arr[index-1]); + + let pastElem; + + return arr.map(function(elem, i) { + if (i == 0) + { + pastElem = elem; + return elem; + } + else + { + elem = elem + pastElem; + pastElem = elem; + return elem; + } + }); + + //throw new Error('Not implemented'); } /** @@ -249,7 +294,9 @@ function getMovingSum(arr) { * [ "a" ] => [] */ function getSecondItems(arr) { - throw new Error('Not implemented'); + return arr.filter((_, i) => i % 2 != 0); + + //throw new Error('Not implemented'); } @@ -268,6 +315,7 @@ function getSecondItems(arr) { * [ 1,2,3,4,5 ] => [ 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5 ] */ function propagateItemsByPositionIndex(arr) { + throw new Error('Not implemented'); } @@ -286,7 +334,9 @@ function propagateItemsByPositionIndex(arr) { * [ 10, 10, 10, 10 ] => [ 10, 10, 10 ] */ function get3TopItems(arr) { - throw new Error('Not implemented'); + return arr.splice(-3).reverse(); + + //throw new Error('Not implemented'); } @@ -304,6 +354,19 @@ function get3TopItems(arr) { * [ 1, '2' ] => 1 */ function getPositivesCount(arr) { + + let count = 0; + + arr.map(function(elem) { + if (typeof elem == "number" && elem > 0) + { + count++; + return elem; + } + }); + + return count; + throw new Error('Not implemented'); } From 7b034dcc8aca1cdd037b43d63c4aab957b413cd9 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Wed, 1 Jul 2020 22:10:44 +0300 Subject: [PATCH 06/11] task 4 1-27 --- task/04-arrays-tasks.js | 105 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index 792937218..535c84dc7 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -240,7 +240,7 @@ function toCsvText(arr) { * [ 10, 100, -1 ] => [ 100, 10000, 1 ] */ function toArrayOfSquares(arr) { - return arr.map((element, _) => element ** 2); + return arr.map((element) => element ** 2); //throw new Error('Not implemented'); } @@ -400,7 +400,17 @@ function sortDigitNamesByNumericOrder(arr) { * [ 1, 10, 100, 1000 ] => 1111 */ function getItemsSum(arr) { - throw new Error('Not implemented'); + + let sum = 0; + + arr.map((element) => { + sum = element + sum; + return element; + }); + + return sum; + + //throw new Error('Not implemented'); } /** @@ -416,7 +426,20 @@ function getItemsSum(arr) { * [ null, undefined, NaN, false, 0, '' ] => 6 */ function getFalsyValuesCount(arr) { - throw new Error('Not implemented'); + + let count = 0; + + arr.map((element) => { + if (Boolean(element) == false) + { + count++; + return element; + } + }); + + return count; + + //throw new Error('Not implemented'); } /** @@ -434,7 +457,20 @@ function getFalsyValuesCount(arr) { * [ true, 0, 1, 'true' ], true => 1 */ function findAllOccurences(arr, item) { - throw new Error('Not implemented'); + + let count = 0; + + arr.map((element) => { + if (element === item) + { + count++; + return element; + } + }); + + return count; + + //throw new Error('Not implemented'); } /** @@ -449,7 +485,25 @@ function findAllOccurences(arr, item) { * ['rock', 'paper', 'scissors'] => 'rock,paper,scissors' */ function toStringList(arr) { - throw new Error('Not implemented'); + + let str = ''; + + arr.map((element, index) => { + if (index + 1 != arr.length) + { + str = str + element + ','; + } + else + { + str = str + element; + } + + return element; + }); + + return str; + + //throw new Error('Not implemented'); } @@ -468,7 +522,7 @@ function toStringList(arr) { * { country: 'Poland', city: 'Krakow' }, * { country: 'Belarus', city: 'Brest' } * ] - * => + * => prev.country > next.country || prev.city > next.city * [ * { country: 'Belarus', city: 'Brest' }, * { country: 'Belarus', city: 'Minsk' }, @@ -478,7 +532,9 @@ function toStringList(arr) { * { country: 'Russia', city: 'Saint Petersburg' } */ function sortCitiesArray(arr) { - throw new Error('Not implemented'); + return arr.sort((prev, next) => ((prev.country > next.country) - (next.country > prev.country) || (prev.city > next.city) - (next.city > prev.city))); + + //throw new Error('Not implemented'); } /** @@ -500,6 +556,22 @@ function sortCitiesArray(arr) { * [0,0,0,0,1]] */ function getIdentityMatrix(n) { +/* + let arr = [n,n]; + + arr.fill(0); + + + + arr.map((_, index) => { + if (index == 0) + { + return 1; + } + }); + + return arr; +*/ throw new Error('Not implemented'); } @@ -517,7 +589,20 @@ function getIdentityMatrix(n) { * 3, 3 => [ 3 ] */ function getIntervalArray(start, end) { - throw new Error('Not implemented'); + + let lengthArr = end - start + 1; + let arr = []; + arr.length = lengthArr; + + arr.fill(start); + + return arr.map(element => { + element = start; + start = start + 1; + return element; + }); + + //throw new Error('Not implemented'); } /** @@ -532,7 +617,9 @@ function getIntervalArray(start, end) { * [ 1, 1, 2, 2, 3, 3, 4, 4] => [ 1, 2, 3, 4] */ function distinct(arr) { - throw new Error('Not implemented'); + return arr.filter((element, index) => arr.indexOf(element) === index); + + //throw new Error('Not implemented'); } /** From 7cbf04dd40124c0a70045afbe486b6f19596ec0f Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Thu, 2 Jul 2020 18:56:35 +0300 Subject: [PATCH 07/11] task 4 nearly-complete --- task/01-strings-tasks.js | 46 ++------------- task/02-numbers-tasks.js | 31 +++------- task/03-date-tasks.js | 33 ++++++++--- task/04-arrays-tasks.js | 118 ++++++++++++++++----------------------- 4 files changed, 86 insertions(+), 142 deletions(-) diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index 655c2da38..980482853 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -23,8 +23,6 @@ */ function concatenateStrings(value1, value2) { return value1 + value2 - - //throw new Error('Not implemented'); } @@ -41,8 +39,6 @@ function concatenateStrings(value1, value2) { */ function getStringLength(value) { return value.length; - - //throw new Error('Not implemented'); } /** @@ -60,8 +56,6 @@ function getStringLength(value) { */ function getStringFromTemplate(firstName, lastName) { return `Hello, ${firstName} ${lastName}!`; - - //throw new Error('Not implemented'); } /** @@ -76,8 +70,6 @@ function getStringFromTemplate(firstName, lastName) { */ function extractNameFromTemplate(value) { return value.replace('Hello, ', '').replace('!', ''); - - //throw new Error('Not implemented'); } @@ -93,8 +85,6 @@ function extractNameFromTemplate(value) { */ function getFirstChar(value) { return value.charAt(0); - - //throw new Error('Not implemented'); } /** @@ -110,8 +100,6 @@ function getFirstChar(value) { */ function removeLeadingAndTrailingWhitespaces(value) { return value.trim(); - - //throw new Error('Not implemented'); } /** @@ -127,8 +115,6 @@ function removeLeadingAndTrailingWhitespaces(value) { */ function repeatString(value, count) { return value.repeat(count); - - //throw new Error('Not implemented'); } /** @@ -145,8 +131,6 @@ function repeatString(value, count) { */ function removeFirstOccurrences(str, value) { return str.replace(value, ''); - - //throw new Error('Not implemented'); } /** @@ -163,8 +147,6 @@ function removeFirstOccurrences(str, value) { function unbracketTag(str) { return str.replace(/[<>]/g, ''); // return str.replace(str[0], '').replace(str[str.length-1], ''); - - //throw new Error('Not implemented'); } @@ -180,8 +162,6 @@ function unbracketTag(str) { */ function convertToUpperCase(str) { return str.toUpperCase(str); - - //throw new Error('Not implemented'); } /** @@ -196,8 +176,6 @@ function convertToUpperCase(str) { */ function extractEmails(str) { return str.split(';'); - - //throw new Error('Not implemented'); } /** @@ -227,8 +205,6 @@ function getRectangleString(width, height) { return '┌' + '─'.repeat(width-2) + '┐' + '\n' + ('│' + ' '.repeat(width-2) + '│\n').repeat(height-2) + '└' + '─'.repeat(width-2) + '┘' + '\n'; - - //throw new Error('Not implemented'); } @@ -248,18 +224,9 @@ function getRectangleString(width, height) { * */ function encodeToRot13(str) { -/* - return str.replace(/[a-zA-Z]/g, function (c) { - return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26); + return str.replace(/[a-zA-Z]/g, function (char) { + return String.fromCharCode((char <= "Z" ? 90 : 122) >= (char = char.charCodeAt(0) + 13) ? char : char - 26); }); - - - function rot13(math) { - return String.fromCharCode((math <= "Z" ? 90 : 122) >= (math = math.charCodeAt(0) + 13) ? math : math - 26); - } - return str.replace(/[a-zA-Z]/g, rot13); -*/ - throw new Error('Not implemented'); } /** @@ -276,10 +243,7 @@ function encodeToRot13(str) { * isString(new String('test')) => true */ function isString(value) { - - //return value ? typeof value.valueOf() == 'string' : false; - - throw new Error('Not implemented'); + return value ? typeof value.valueOf() == 'string' : false; } @@ -308,7 +272,9 @@ function isString(value) { * 'K♠' => 51 */ function getCardId(value) { - throw new Error('Not implemented'); + let cardsArr = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; + let suitsArr = ['♣', '♦', '♥', '♠']; + return cardsArr.indexOf(value.slice(0, -1)) + suitsArr.indexOf(value.slice(-1)) * cardsArr.length; } diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index dcd44e895..19cbe2509 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -23,8 +23,6 @@ */ function getRectangleArea(width, height) { return width*height; - - //throw new Error('Not implemented'); } @@ -41,8 +39,6 @@ function getRectangleArea(width, height) { */ function getCicleCircumference(radius) { return 2 * Math.PI * radius; - - //throw new Error('Not implemented'); } /** @@ -59,8 +55,6 @@ function getCicleCircumference(radius) { */ function getAverage(value1, value2) { return value1 / 2 + value2 / 2; - - //throw new Error('Not implemented'); } /** @@ -79,9 +73,7 @@ function getAverage(value1, value2) { * (-5,0) (10,-10) => 18.027756377319946 */ function getDistanceBetweenPoints(x1, y1, x2, y2) { - return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2); - - //throw new Error('Not implemented'); + return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)); } /** @@ -98,8 +90,6 @@ function getDistanceBetweenPoints(x1, y1, x2, y2) { */ function getLinearEquationRoot(a, b) { return (-b) / a; - - //throw new Error('Not implemented'); } @@ -121,7 +111,7 @@ function getLinearEquationRoot(a, b) { * (0,1) (1,2) => 0 */ function getAngleBetweenVectors(x1, y1, x2, y2) { - throw new Error('Not implemented'); + return Math.acos((x1 * x2 + y1 * y2) / (Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2) ) * Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2)))); } /** @@ -138,8 +128,6 @@ function getAngleBetweenVectors(x1, y1, x2, y2) { */ function getLastDigit(value) { return value % 10; - - //throw new Error('Not implemented'); } @@ -156,8 +144,6 @@ function getLastDigit(value) { */ function parseNumberFromString(value) { return +value; - - //throw new Error('Not implemented'); } /** @@ -175,8 +161,6 @@ function parseNumberFromString(value) { */ function getParallelipidedDiagonal(a,b,c) { return Math.sqrt(a ** 2 + b ** 2 + c ** 2); - - //throw new Error('Not implemented'); } /** @@ -198,8 +182,6 @@ function getParallelipidedDiagonal(a,b,c) { */ function roundToPowerOfTen(num, pow) { return Math.round(num / (10 ** pow)) * (10 ** pow); - - //throw new Error('Not implemented'); } /** @@ -220,7 +202,12 @@ function roundToPowerOfTen(num, pow) { * 17 => true */ function isPrime(n) { - throw new Error('Not implemented'); + for (let i = 2; i < n; i++) { + if (n % i === 0) { + return false; + } + } + return true; } /** @@ -239,7 +226,7 @@ function isPrime(n) { * toNumber(new Number(42), 0) => 42 */ function toNumber(value, def) { - throw new Error('Not implemented'); + return +value ? value : def; } module.exports = { diff --git a/task/03-date-tasks.js b/task/03-date-tasks.js index 94c04b9f0..39971f94f 100644 --- a/task/03-date-tasks.js +++ b/task/03-date-tasks.js @@ -90,21 +90,17 @@ function timeSpanToString(startDate, endDate) { let dateDif = endDate - startDate; let date = new Date(); - /* let hour = Math.floor(dateDif / 3.6e6); let min = Math.floor((dateDif - hour * 3.6e6) / 6e4); let sec = Math.floor((dateDif - hour * 3.6e6 - min * 6e4) / 1e3); let ms = dateDif - hour * 3.6e6 - min * 6e4 - sec * 1e3; - - +/* date.setHours(Math.floor(dateDif / 3.6e6)); date.setMinutes(Math.floor((dateDif % 3.6e6) / 6e4)); - date.setSeconds(Math.floor((dateDif % 3.6e6 % 6e4) / 1e3)); + date.setSegeconds(Math.floor((dateDif % 3.6e6 % 6e4) / 1e3)); date.setMilliseconds(dateDif % 3.6e6 % 6e4 % 1e3); - - return date.getHours(); - */ - throw new Error('Not implemented'); +*/ + return ('0' + hour).slice(-2) + ':' + ('0' + min).slice(-2) + ':' + ('0' + sec).slice(-2) + '.' + (ms + '00').slice(0, 3); } @@ -116,16 +112,35 @@ function timeSpanToString(startDate, endDate) { * @return {number} * * @example: + * * Date.UTC(2016,2,5, 0, 0) => 0 * Date.UTC(2016,3,5, 3, 0) => Math.PI/2 * Date.UTC(2016,3,5,18, 0) => Math.PI * Date.UTC(2016,3,5,21, 0) => Math.PI/2 */ function angleBetweenClockHands(date) { - throw new Error('Not implemented'); + + /* + let minuteDegree = 0; + let hourDegree = 0; + + let newDate = new Date(date); + + minuteDegree = newDate.getUTCMinutes () * (360 / 60); + minuteDegree != 0 ? hourDegree = newDate.getUTCHours() * (360 / 12) + ((360 / 12) / (60 / minuteDegree)) : hourDegree = newDate.getUTCHours() * (360 / 12); + + return Math.sin(Math.abs(minuteDegree - hourDegree)); + */ + /* + let degree = 0.5 * (60 * date.getUTCHours() - 11 * date.getUTCHours()); + let totalDegree = degree > 180 ? 360 - degree : degree; + return Math.PI/180 * totalDegree; + */ + throw new Error('Not implemented'); } + module.exports = { parseDataFromRfc2822: parseDataFromRfc2822, parseDataFromIso8601: parseDataFromIso8601, diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index 535c84dc7..91ecd204b 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -25,7 +25,7 @@ const { parseDataFromRfc2822 } = require("./03-date-tasks"); * [0, 1, 2, 3, 4, 5], 5 => 5 */ function findElement(arr, value) { - throw new Error('Not implemented'); + return arr.indexOf(value); } /** @@ -43,7 +43,6 @@ function generateOdds(len) { return new Array(len).fill(0).map(function(_, i) { return 2 * i + 1; }); - //throw new Error('Not implemented'); } @@ -59,10 +58,7 @@ function generateOdds(len) { * [] => [] */ function doubleArray(arr) { - return [...arr, ...arr]; - - //throw new Error('Not implemented'); } @@ -79,8 +75,6 @@ function doubleArray(arr) { */ function getArrayOfPositives(arr) { return arr.filter(arr => arr > 0); - - //throw new Error('Not implemented'); } /** @@ -96,8 +90,6 @@ function getArrayOfPositives(arr) { */ function getArrayOfStrings(arr) { return arr.filter(arr => typeof arr == "string"); - - //throw new Error('Not implemented'); } /** @@ -115,8 +107,6 @@ function getArrayOfStrings(arr) { */ function removeFalsyValues(arr) { return arr.filter(arr => Boolean(arr) == true ); - - //throw new Error('Not implemented'); } /** @@ -131,8 +121,6 @@ function removeFalsyValues(arr) { */ function getUpperCaseStrings(arr) { return arr.map((element, _) => element.toUpperCase()); - - //throw new Error('Not implemented'); } @@ -148,8 +136,6 @@ function getUpperCaseStrings(arr) { */ function getStringsLength(arr) { return arr.map((element, _) => element.length); - - //throw new Error('Not implemented'); } /** @@ -165,8 +151,6 @@ function getStringsLength(arr) { */ function insertItem(arr, item, index) { return arr.splice(index, 0, item); - - //throw new Error('Not implemented'); } /** @@ -182,8 +166,6 @@ function insertItem(arr, item, index) { function getHead(arr, n) { let delered = arr.splice(n); return arr; - - //throw new Error('Not implemented'); } @@ -199,8 +181,6 @@ function getHead(arr, n) { */ function getTail(arr, n) { return arr.splice(-n); - - //throw new Error('Not implemented'); } @@ -225,7 +205,13 @@ function getTail(arr, n) { * +'30,31,32,33,34' */ function toCsvText(arr) { + + + throw new Error('Not implemented'); + + + } /** @@ -241,8 +227,6 @@ function toCsvText(arr) { */ function toArrayOfSquares(arr) { return arr.map((element) => element ** 2); - - //throw new Error('Not implemented'); } @@ -262,9 +246,7 @@ function toArrayOfSquares(arr) { */ function getMovingSum(arr) { //return arr.map((element, index) => arr[index] == arr[0] ? arr[index] = arr[index] : arr[index] = arr[index] + arr[index-1]); - let pastElem; - return arr.map(function(elem, i) { if (i == 0) { @@ -278,8 +260,6 @@ function getMovingSum(arr) { return elem; } }); - - //throw new Error('Not implemented'); } /** @@ -295,8 +275,6 @@ function getMovingSum(arr) { */ function getSecondItems(arr) { return arr.filter((_, i) => i % 2 != 0); - - //throw new Error('Not implemented'); } @@ -315,8 +293,13 @@ function getSecondItems(arr) { * [ 1,2,3,4,5 ] => [ 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5 ] */ function propagateItemsByPositionIndex(arr) { - + + + throw new Error('Not implemented'); + + + } @@ -335,8 +318,6 @@ function propagateItemsByPositionIndex(arr) { */ function get3TopItems(arr) { return arr.splice(-3).reverse(); - - //throw new Error('Not implemented'); } @@ -354,9 +335,7 @@ function get3TopItems(arr) { * [ 1, '2' ] => 1 */ function getPositivesCount(arr) { - let count = 0; - arr.map(function(elem) { if (typeof elem == "number" && elem > 0) { @@ -364,10 +343,7 @@ function getPositivesCount(arr) { return elem; } }); - return count; - - throw new Error('Not implemented'); } /** @@ -384,7 +360,13 @@ function getPositivesCount(arr) { * [ 'one','one','one','zero' ] => [ 'zero','one','one','one' ] */ function sortDigitNamesByNumericOrder(arr) { + + + throw new Error('Not implemented'); + + + } /** @@ -400,17 +382,12 @@ function sortDigitNamesByNumericOrder(arr) { * [ 1, 10, 100, 1000 ] => 1111 */ function getItemsSum(arr) { - let sum = 0; - arr.map((element) => { sum = element + sum; return element; }); - return sum; - - //throw new Error('Not implemented'); } /** @@ -426,9 +403,7 @@ function getItemsSum(arr) { * [ null, undefined, NaN, false, 0, '' ] => 6 */ function getFalsyValuesCount(arr) { - let count = 0; - arr.map((element) => { if (Boolean(element) == false) { @@ -436,10 +411,7 @@ function getFalsyValuesCount(arr) { return element; } }); - return count; - - //throw new Error('Not implemented'); } /** @@ -457,9 +429,7 @@ function getFalsyValuesCount(arr) { * [ true, 0, 1, 'true' ], true => 1 */ function findAllOccurences(arr, item) { - let count = 0; - arr.map((element) => { if (element === item) { @@ -467,10 +437,7 @@ function findAllOccurences(arr, item) { return element; } }); - return count; - - //throw new Error('Not implemented'); } /** @@ -485,9 +452,7 @@ function findAllOccurences(arr, item) { * ['rock', 'paper', 'scissors'] => 'rock,paper,scissors' */ function toStringList(arr) { - let str = ''; - arr.map((element, index) => { if (index + 1 != arr.length) { @@ -497,13 +462,9 @@ function toStringList(arr) { { str = str + element; } - return element; }); - return str; - - //throw new Error('Not implemented'); } @@ -533,8 +494,6 @@ function toStringList(arr) { */ function sortCitiesArray(arr) { return arr.sort((prev, next) => ((prev.country > next.country) - (next.country > prev.country) || (prev.city > next.city) - (next.city > prev.city))); - - //throw new Error('Not implemented'); } /** @@ -589,20 +548,15 @@ function getIdentityMatrix(n) { * 3, 3 => [ 3 ] */ function getIntervalArray(start, end) { - let lengthArr = end - start + 1; let arr = []; arr.length = lengthArr; - arr.fill(start); - return arr.map(element => { element = start; start = start + 1; return element; - }); - - //throw new Error('Not implemented'); + }); } /** @@ -618,8 +572,6 @@ function getIntervalArray(start, end) { */ function distinct(arr) { return arr.filter((element, index) => arr.indexOf(element) === index); - - //throw new Error('Not implemented'); } /** @@ -653,7 +605,13 @@ function distinct(arr) { * } */ function group(array, keySelector, valueSelector) { + + + throw new Error('Not implemented'); + + + } @@ -669,7 +627,13 @@ function group(array, keySelector, valueSelector) { * ['one','two','three'], x=>x.split('') => ['o','n','e','t','w','o','t','h','r','e','e'] */ function selectMany(arr, childrenSelector) { - throw new Error('Not implemented'); + + + + throw new Error('Not implemented'); + + + } @@ -686,7 +650,13 @@ function selectMany(arr, childrenSelector) { * [[[ 1, 2, 3]]], [ 0, 0, 1 ] => 2 (arr[0][0][1]) */ function getElementByIndexes(arr, indexes) { - throw new Error('Not implemented'); + + + + throw new Error('Not implemented'); + + + } @@ -709,7 +679,13 @@ function getElementByIndexes(arr, indexes) { * */ function swapHeadAndTail(arr) { - throw new Error('Not implemented'); + + + + throw new Error('Not implemented'); + + + } From 21600fd3c169747bd624388b6ddae68dac46bc6f Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Thu, 2 Jul 2020 19:01:47 +0300 Subject: [PATCH 08/11] task 4 nearly-complete#2 --- task/02-numbers-tasks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index 19cbe2509..6f9d3525b 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -160,7 +160,7 @@ function parseNumberFromString(value) { * 1,2,3 => 3.741657386773941 */ function getParallelipidedDiagonal(a,b,c) { - return Math.sqrt(a ** 2 + b ** 2 + c ** 2); + return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) + Math.pow(c, 2)); } /** @@ -181,7 +181,7 @@ function getParallelipidedDiagonal(a,b,c) { * 1678, 3 => 2000 */ function roundToPowerOfTen(num, pow) { - return Math.round(num / (10 ** pow)) * (10 ** pow); + return Math.round(num / (Math.pow(10, pow) * Math.pow(10, pow))); } /** From 73240863333d4c026aeb2dfe921fdce03ce34e00 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Tue, 7 Jul 2020 11:10:25 +0300 Subject: [PATCH 09/11] task 4 nearly-complete#3 --- .travis.yml | 1 - task/02-numbers-tasks.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 008cbc167..3791fa402 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,2 @@ language: node_js node_js: - - "5.10.0" diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index 6f9d3525b..eb79c7b7a 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -160,7 +160,7 @@ function parseNumberFromString(value) { * 1,2,3 => 3.741657386773941 */ function getParallelipidedDiagonal(a,b,c) { - return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) + Math.pow(c, 2)); + return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) + Math.pow(c, 2)); } /** @@ -181,7 +181,7 @@ function getParallelipidedDiagonal(a,b,c) { * 1678, 3 => 2000 */ function roundToPowerOfTen(num, pow) { - return Math.round(num / (Math.pow(10, pow) * Math.pow(10, pow))); + return Math.round(num / (10 ** pow)) * (10 ** pow); } /** From bb619555b7027b82dee7ef2b6fef94d4b62ddc3e Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Tue, 7 Jul 2020 11:12:32 +0300 Subject: [PATCH 10/11] task 4 nearly-complete#4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3791fa402..b0e500072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,3 @@ language: node_js node_js: + - "12.18.2" From 241209584d300e04c82680d2f538cceabc080535 Mon Sep 17 00:00:00 2001 From: GENSECvkpb <44395857+GENSECvkpb@users.noreply.github.com> Date: Fri, 10 Jul 2020 06:29:42 +0300 Subject: [PATCH 11/11] Task1-4#done --- task/03-date-tasks.js | 49 +++++++++++++-- task/04-arrays-tasks.js | 133 +++++++++++++++++++--------------------- 2 files changed, 106 insertions(+), 76 deletions(-) diff --git a/task/03-date-tasks.js b/task/03-date-tasks.js index 39971f94f..5b902a153 100644 --- a/task/03-date-tasks.js +++ b/task/03-date-tasks.js @@ -119,23 +119,60 @@ function timeSpanToString(startDate, endDate) { * Date.UTC(2016,3,5,21, 0) => Math.PI/2 */ function angleBetweenClockHands(date) { - - /* +/* + let minuteDegree = 0; let hourDegree = 0; let newDate = new Date(date); - minuteDegree = newDate.getUTCMinutes () * (360 / 60); - minuteDegree != 0 ? hourDegree = newDate.getUTCHours() * (360 / 12) + ((360 / 12) / (60 / minuteDegree)) : hourDegree = newDate.getUTCHours() * (360 / 12); + minuteDegree = newDate.getMinutes() * (360 / 60); + minuteDegree != 0 ? hourDegree = newDate.getHours() * (360 / 12) + ((360 / 12) / (60 / minuteDegree)) : hourDegree = newDate.getHours() * (360 / 12); + + console.log("Время - " + date); + console.log("Минутная - " + minuteDegree); + console.log("Часовая - " + hourDegree); + + console.log("Градусы - " + Math.sin(Math.abs(minuteDegree - hourDegree))); + console.log(" "); return Math.sin(Math.abs(minuteDegree - hourDegree)); - */ - /* + let degree = 0.5 * (60 * date.getUTCHours() - 11 * date.getUTCHours()); let totalDegree = degree > 180 ? 360 - degree : degree; return Math.PI/180 * totalDegree; */ + + let map = new Map(); + let newDate = new Date(date); + let hour = newDate.getUTCHours(); + let min = newDate.getUTCMinutes(); + let hour2; + let mih; + let ang; + let result; + + if (hour >= 12) hour -= 12; + + map.set(0, 0) + .set(30, Math.PI / 6) + .set(45, Math.PI / 4) + .set(60, Math.PI / 3) + .set(90, Math.PI / 2) + .set(180, Math.PI); + + hour2 = 0.5 * (60 * hour + min); + mih = 6 * min; + ang = Math.abs(hour2 - mih); + + if (ang > 180) ang -= 180; + + result = map.get(Math.abs(ang)); + + if (result == null && result == undefined) + return ang * Math.PI / 180 + else + return result; throw new Error('Not implemented'); } diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index 91ecd204b..784ba2233 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -135,7 +135,7 @@ function getUpperCaseStrings(arr) { * [ 'angular', 'react', 'ember' ] => [ 7, 5, 5 ] */ function getStringsLength(arr) { - return arr.map((element, _) => element.length); + return arr.map((element) => element.length); } /** @@ -165,6 +165,7 @@ function insertItem(arr, item, index) { */ function getHead(arr, n) { let delered = arr.splice(n); + return arr; } @@ -205,13 +206,9 @@ function getTail(arr, n) { * +'30,31,32,33,34' */ function toCsvText(arr) { + let newArr = arr.map(element => element.join(',') + '\n').join(''); - - - throw new Error('Not implemented'); - - - + return newArr.slice(0, newArr.length - 1); } /** @@ -247,8 +244,8 @@ function toArrayOfSquares(arr) { function getMovingSum(arr) { //return arr.map((element, index) => arr[index] == arr[0] ? arr[index] = arr[index] : arr[index] = arr[index] + arr[index-1]); let pastElem; - return arr.map(function(elem, i) { - if (i == 0) + return arr.map(function(elem, index) { + if (index == 0) { pastElem = elem; return elem; @@ -274,7 +271,7 @@ function getMovingSum(arr) { * [ "a" ] => [] */ function getSecondItems(arr) { - return arr.filter((_, i) => i % 2 != 0); + return arr.filter((_, index) => index % 2 != 0); } @@ -293,13 +290,14 @@ function getSecondItems(arr) { * [ 1,2,3,4,5 ] => [ 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5 ] */ function propagateItemsByPositionIndex(arr) { - - - - throw new Error('Not implemented'); - - - + let newArr = []; + arr.filter((element, index) => { + let insArr = new Array(index + 1); + insArr.fill(element); + newArr.push(...insArr); + }); + + return newArr; } @@ -336,13 +334,14 @@ function get3TopItems(arr) { */ function getPositivesCount(arr) { let count = 0; - arr.map(function(elem) { - if (typeof elem == "number" && elem > 0) + arr.map(function(element) { + if (typeof element == "number" && element > 0) { count++; - return elem; + return element; } }); + return count; } @@ -360,13 +359,9 @@ function getPositivesCount(arr) { * [ 'one','one','one','zero' ] => [ 'zero','one','one','one' ] */ function sortDigitNamesByNumericOrder(arr) { - - - - throw new Error('Not implemented'); - - - + const numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; + + return arr.sort((firstElement, secondElement) => { return numbers.indexOf(firstElement) - numbers.indexOf(secondElement) }); } /** @@ -387,6 +382,7 @@ function getItemsSum(arr) { sum = element + sum; return element; }); + return sum; } @@ -411,6 +407,7 @@ function getFalsyValuesCount(arr) { return element; } }); + return count; } @@ -437,6 +434,7 @@ function findAllOccurences(arr, item) { return element; } }); + return count; } @@ -464,6 +462,7 @@ function toStringList(arr) { } return element; }); + return str; } @@ -515,23 +514,12 @@ function sortCitiesArray(arr) { * [0,0,0,0,1]] */ function getIdentityMatrix(n) { -/* - let arr = [n,n]; - - arr.fill(0); - - - - arr.map((_, index) => { - if (index == 0) - { - return 1; - } - }); - - return arr; -*/ - throw new Error('Not implemented'); + let newArr = new Array(n).fill(0); + return newArr.map((element, index) => { + let rowArr = new Array(n).fill(0); + rowArr[index] = 1; + return element = rowArr; + }); } /** @@ -605,13 +593,24 @@ function distinct(arr) { * } */ function group(array, keySelector, valueSelector) { + let key = array.map(keySelector); + let value = array.map(valueSelector); + let map = new Map(); + + key.filter((element, index) => { + if (!map.has(element)) + { + map.set(element, [value[index]]); + } + else + { + let value2 = map.get(element); + value2.push(value[index]); + map.set(element, value2); + } + }); - - - throw new Error('Not implemented'); - - - + return map; } @@ -627,13 +626,12 @@ function group(array, keySelector, valueSelector) { * ['one','two','three'], x=>x.split('') => ['o','n','e','t','w','o','t','h','r','e','e'] */ function selectMany(arr, childrenSelector) { + let newArr = []; + arr.map(element => { + newArr.push(...childrenSelector(element)); + }); - - - throw new Error('Not implemented'); - - - + return newArr; } @@ -650,13 +648,7 @@ function selectMany(arr, childrenSelector) { * [[[ 1, 2, 3]]], [ 0, 0, 1 ] => 2 (arr[0][0][1]) */ function getElementByIndexes(arr, indexes) { - - - - throw new Error('Not implemented'); - - - + return indexes.reduce((newArr, index) => newArr[index], arr); } @@ -679,13 +671,14 @@ function getElementByIndexes(arr, indexes) { * */ function swapHeadAndTail(arr) { - - - - throw new Error('Not implemented'); - - - + let arr2; + let lenghtArr = arr.length; + let head = arr.slice(0, (lenghtArr / 2)); + let tail = arr.slice( -(lenghtArr / 2)); + + if (lenghtArr % 2 != 0 && lenghtArr > 1) return arr2 = [...tail, arr[Math.floor(lenghtArr / 2)], ...head]; + + return arr2 = [...tail, ...head];; }