From 72e69c2ac66a0b77cfbbf9b1645c0870583cda55 Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 16:31:43 +0300 Subject: [PATCH 1/6] Adds 1-4 tasks solutions --- task/01-strings-tasks.js | 54 ++++++++---- task/02-numbers-tasks.js | 40 ++++++--- task/03-date-tasks.js | 40 +++++++-- task/04-arrays-tasks.js | 185 ++++++++++++++++++++++++++++++++------- 4 files changed, 252 insertions(+), 67 deletions(-) diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index e28054657..82b6d598a 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -22,7 +22,7 @@ * '', 'bb' => 'bb' */ function concatenateStrings(value1, value2) { - throw new Error('Not implemented'); + return value1+value2; } @@ -38,7 +38,7 @@ function concatenateStrings(value1, value2) { * '' => 0 */ function getStringLength(value) { - throw new Error('Not implemented'); + return value.length; } /** @@ -55,7 +55,7 @@ function getStringLength(value) { * 'Chuck','Norris' => 'Hello, Chuck Norris!' */ function getStringFromTemplate(firstName, lastName) { - throw new Error('Not implemented'); + return `Hello, ${firstName} ${lastName}!`; } /** @@ -69,7 +69,7 @@ function getStringFromTemplate(firstName, lastName) { * 'Hello, Chuck Norris!' => 'Chuck Norris' */ function extractNameFromTemplate(value) { - throw new Error('Not implemented'); + return value.substring(7,value.length-1); } @@ -84,7 +84,7 @@ function extractNameFromTemplate(value) { * 'cat' => 'c' */ function getFirstChar(value) { - throw new Error('Not implemented'); + return value.substring(0,1); } /** @@ -99,7 +99,7 @@ function getFirstChar(value) { * '\tHello, World! ' => 'Hello, World!' */ function removeLeadingAndTrailingWhitespaces(value) { - throw new Error('Not implemented'); + return value.trim(); } /** @@ -114,7 +114,7 @@ function removeLeadingAndTrailingWhitespaces(value) { * 'cat', 3 => 'catcatcat' */ function repeatString(value, count) { - throw new Error('Not implemented'); + return value.repeat(count); } /** @@ -130,7 +130,7 @@ function repeatString(value, count) { * 'ABABAB','BA' => 'ABAB' */ function removeFirstOccurrences(str, value) { - throw new Error('Not implemented'); + return str.replace(value, ""); } /** @@ -145,7 +145,7 @@ function removeFirstOccurrences(str, value) { * '' => 'a' */ function unbracketTag(str) { - throw new Error('Not implemented'); + return str.replace(/[\<\>]+/g, ""); } @@ -160,7 +160,7 @@ function unbracketTag(str) { * 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' */ function convertToUpperCase(str) { - throw new Error('Not implemented'); + return str.toLocaleUpperCase(); } /** @@ -174,7 +174,7 @@ function convertToUpperCase(str) { * 'info@gmail.com' => ['info@gmail.com'] */ function extractEmails(str) { - throw new Error('Not implemented'); + return str.split(";") ; } /** @@ -201,7 +201,12 @@ function extractEmails(str) { * */ function getRectangleString(width, height) { - throw new Error('Not implemented'); + let top = `┌${'─'.repeat(width -2)}┐\n` ; + let side = `│${' '.repeat(width -2)}│\n`; + let bottom = `└${'─'.repeat(width -2)}┘\n`; + + console.log(top + side.repeat(height - 2) + bottom) + return top + side.repeat(height - 2) + bottom; } @@ -221,7 +226,11 @@ function getRectangleString(width, height) { * */ function encodeToRot13(str) { - throw new Error('Not implemented'); + let input = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + let output = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'; + let index = x => input.indexOf(x); + let translate = x => index(x) > -1 ? output[index(x)] : x; + return str.split('').map(translate).join(''); } /** @@ -238,7 +247,14 @@ function encodeToRot13(str) { * isString(new String('test')) => true */ function isString(value) { - throw new Error('Not implemented'); + let val; + if (typeof value === 'string') { + val = value; + } + if (typeof value === 'object' && value !== null && !Array.isArray(value)) { + val = value.valueOf() + } + return (typeof val === 'string') } @@ -267,9 +283,15 @@ function isString(value) { * 'K♠' => 51 */ function getCardId(value) { - throw new Error('Not implemented'); -} + const cards = [ + 'A♣','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣', + 'A♦','2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦', + 'A♥','2♥','3♥','4♥','5♥','6♥','7♥','8♥','9♥','10♥','J♥','Q♥','K♥', + 'A♠','2♠','3♠','4♠','5♠','6♠','7♠','8♠','9♠','10♠','J♠','Q♠','K♠' + ]; + return cards.indexOf(value); +} module.exports = { concatenateStrings: concatenateStrings, diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index c9ed20208..aaff3a95f 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -22,7 +22,7 @@ * 5, 5 => 25 */ function getRectangleArea(width, height) { - throw new Error('Not implemented'); + return width * height; } @@ -38,7 +38,7 @@ function getRectangleArea(width, height) { * 0 => 0 */ function getCicleCircumference(radius) { - throw new Error('Not implemented'); + return 2*Math.sqrt*radius; } /** @@ -54,7 +54,10 @@ function getCicleCircumference(radius) { * -3, 3 => 0 */ function getAverage(value1, value2) { - throw new Error('Not implemented'); + if (value1 === value2) { + return value1 + } + return ((value1 + value2) / 2); } /** @@ -73,7 +76,7 @@ function getAverage(value1, value2) { * (-5,0) (10,-10) => 18.027756377319946 */ function getDistanceBetweenPoints(x1, y1, x2, y2) { - throw new Error('Not implemented'); + return Math.sqrt(((x2-x1)**2) +((y2-y1)**2)); } /** @@ -89,7 +92,7 @@ function getDistanceBetweenPoints(x1, y1, x2, y2) { * 5*x = 0 => 0 */ function getLinearEquationRoot(a, b) { - throw new Error('Not implemented'); + return ((-b)/a); } @@ -111,7 +114,7 @@ function getLinearEquationRoot(a, b) { * (0,1) (1,2) => 0 */ function getAngleBetweenVectors(x1, y1, x2, y2) { - throw new Error('Not implemented'); + return Math.abs(Math.atan(y1 / x1) - Math.atan(y2 / x2)) } /** @@ -127,7 +130,8 @@ function getAngleBetweenVectors(x1, y1, x2, y2) { * 0 => 0 */ function getLastDigit(value) { - throw new Error('Not implemented'); + const lastChar = value.toString()[value.toString().length - 1]; + return +lastChar; } @@ -143,7 +147,7 @@ function getLastDigit(value) { * '-525.5' => -525.5 */ function parseNumberFromString(value) { - throw new Error('Not implemented'); + return +value } /** @@ -160,7 +164,7 @@ 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) } /** @@ -181,7 +185,10 @@ function getParallelipidedDiagonal(a,b,c) { * 1678, 3 => 2000 */ function roundToPowerOfTen(num, pow) { - throw new Error('Not implemented'); + if (pow === 0){ + return num; + } + return Math.round(num/(10**pow)) * 10**pow; } /** @@ -202,7 +209,13 @@ function roundToPowerOfTen(num, pow) { * 17 => true */ function isPrime(n) { - throw new Error('Not implemented'); + for(let i = 2; i < n; i++) { + console.log(n, i) + if(n % i === 0) { + return false; + } + } + return n > 1; } /** @@ -221,7 +234,10 @@ function isPrime(n) { * toNumber(new Number(42), 0) => 42 */ function toNumber(value, def) { - throw new Error('Not implemented'); + if (value !== null && Number.isInteger(+value)) { + return +value + } + return def; } module.exports = { diff --git a/task/03-date-tasks.js b/task/03-date-tasks.js index 83c6266bc..7ab3854d3 100644 --- a/task/03-date-tasks.js +++ b/task/03-date-tasks.js @@ -22,7 +22,7 @@ * 'Sun, 17 May 1998 03:00:00 GMT+01' => Date() */ function parseDataFromRfc2822(value) { - throw new Error('Not implemented'); + return Date.parse(value) ; } /** @@ -37,7 +37,7 @@ function parseDataFromRfc2822(value) { * '2016-01-19T08:07:37Z' => Date() */ function parseDataFromIso8601(value) { - throw new Error('Not implemented'); + return Date.parse(value); } @@ -56,7 +56,14 @@ function parseDataFromIso8601(value) { * Date(2015,1,1) => false */ function isLeapYear(date) { - throw new Error('Not implemented'); + let year = date.getFullYear(); + if (year % 400 === 0 || year % 100 !==0){ + if (year % 4 ===0){ + return true; + } + } + return false; + } @@ -76,7 +83,26 @@ 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) { - throw new Error('Not implemented'); + let hours = (endDate.getDay() - startDate.getDay()) * 24 + endDate.getHours() - startDate.getHours(); + if (hours < 10){ + hours = '0' + hours; + } + let minutes = endDate.getMinutes() - startDate.getMinutes(); + if (minutes < 10){ + minutes = '0' + minutes; + } + let seconds = endDate.getSeconds() - startDate.getSeconds(); + if (seconds < 10){ + seconds = '0' + seconds; + } + let milliseconds = endDate.getMilliseconds() - startDate.getMilliseconds(); + if (milliseconds < 100 && milliseconds >= 10){ + milliseconds = '0' + milliseconds; + } + if (milliseconds < 10){ + milliseconds = '00' + milliseconds + }; + return `${hours}:${minutes}:${seconds}.${milliseconds}`; } @@ -94,7 +120,11 @@ function timeSpanToString(startDate, endDate) { * Date.UTC(2016,3,5,21, 0) => Math.PI/2 */ function angleBetweenClockHands(date) { - throw new Error('Not implemented'); + const hour = date.getUTCHours() > 12 ? date.getUTCHours() - 12 : date.getUTCHours(); + const minutes = date.getUTCMinutes() * 6; + const hours = 0.5 * (60 * hour + date.getUTCMinutes()); + const angle = hours - minutes > 180 ? hours - minutes - 180 : hours - minutes; + return (Math.abs(angle) * Math.PI)/180; } diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index ff3a4c019..374e1c93e 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -23,7 +23,11 @@ * [0, 1, 2, 3, 4, 5], 5 => 5 */ function findElement(arr, value) { - throw new Error('Not implemented'); + if (arr.find((el) => el === value)) { + return arr.indexOf(value); + } else { + return '-1' + } } /** @@ -38,7 +42,8 @@ function findElement(arr, value) { * 5 => [ 1, 3, 5, 7, 9 ] */ function generateOdds(len) { - throw new Error('Not implemented'); + let arr = new Array(len).fill(2); + return arr.map((el, i) => el * i + 1); } @@ -54,7 +59,7 @@ function generateOdds(len) { * [] => [] */ function doubleArray(arr) { - throw new Error('Not implemented'); + return arr.concat(arr); } @@ -70,7 +75,13 @@ function doubleArray(arr) { * [] => [] */ function getArrayOfPositives(arr) { - throw new Error('Not implemented'); + let arrPos = []; + arr.map((el)=>{ + if(el > 0){ + arrPos.push(el) + } + }); + return arrPos; } /** @@ -85,7 +96,8 @@ function getArrayOfPositives(arr) { * [ 'cat, 'dog', 'raccon' ] => [ 'cat', 'dog', 'racoon' ] */ function getArrayOfStrings(arr) { - throw new Error('Not implemented'); + return arr.filter((el) => typeof el === "string"); + } /** @@ -101,8 +113,14 @@ function getArrayOfStrings(arr) { * [ 1, 2, 3, 4, 5, 'false' ] => [ 1, 2, 3, 4, 5, 'false' ] * [ false, 0, NaN, '', undefined ] => [ ] */ -function removeFalsyValues(arr) { - throw new Error('Not implemented'); +function removeFalsyValues(arr){ + let newArr = []; + arr.map((el) =>{ + if (Boolean(el) !== false){ + newArr.push(el); + } + }) + return newArr; } /** @@ -116,7 +134,7 @@ 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((index) => index.toUpperCase()); } @@ -131,7 +149,7 @@ function getUpperCaseStrings(arr) { * [ 'angular', 'react', 'ember' ] => [ 7, 5, 5 ] */ function getStringsLength(arr) { - throw new Error('Not implemented'); + return arr.map((el) => el.length); } /** @@ -146,7 +164,7 @@ 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); } /** @@ -160,7 +178,8 @@ function insertItem(arr, item, index) { * [ 'a', 'b', 'c', 'd'], 3 => [ 'a', 'b', 'c' ] */ function getHead(arr, n) { - throw new Error('Not implemented'); + arr.length = n; + return arr; } @@ -175,7 +194,7 @@ function getHead(arr, n) { * [ 'a', 'b', 'c', 'd'], 3 => [ 'b', 'c', 'd' ] */ function getTail(arr, n) { - throw new Error('Not implemented'); + return arr.splice(arr.length - n, n); } @@ -200,7 +219,7 @@ function getTail(arr, n) { * +'30,31,32,33,34' */ function toCsvText(arr) { - throw new Error('Not implemented'); + return arr.map((el) => el.join(",")).join("\n"); } /** @@ -215,7 +234,7 @@ function toCsvText(arr) { * [ 10, 100, -1 ] => [ 100, 10000, 1 ] */ function toArrayOfSquares(arr) { - throw new Error('Not implemented'); + return arr.map((el) => el * el); } @@ -234,7 +253,12 @@ 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'); + let newArr = []; + arr.reduce((accum, curr) =>{ + newArr.push(accum + curr); + return accum + curr; + }, 0); + return newArr; } /** @@ -249,7 +273,13 @@ function getMovingSum(arr) { * [ "a" ] => [] */ function getSecondItems(arr) { - throw new Error('Not implemented'); + let newArr = []; + arr.map((el) =>{ + if (arr.indexOf(el) % 2 !== 0){ + newArr.push(el); + } + }); + return newArr; } @@ -268,7 +298,15 @@ 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.map((el, index) =>{ + if (index + 1 > 1){ + newArr = newArr.concat(Array(index + 1).fill(el)) + } else { + newArr.push(el); + } + }); + return newArr; } @@ -286,12 +324,16 @@ function propagateItemsByPositionIndex(arr) { * [ 10, 10, 10, 10 ] => [ 10, 10, 10 ] */ function get3TopItems(arr) { - throw new Error('Not implemented'); + let newArr = arr.reverse(); + if (arr.length > 3) { + newArr.length = 3; + } + return newArr; } /** - * Returns the number of positive numbers from specified array + * * * @param {array} arr * @return {number} @@ -304,7 +346,15 @@ function get3TopItems(arr) { * [ 1, '2' ] => 1 */ function getPositivesCount(arr) { - throw new Error('Not implemented'); + let newArr = []; + if (arr.length) { + arr.map((el) => { + if (typeof el === "number" && el > 0) { + newArr.push(el) + } + }); + } + return newArr.length; } /** @@ -321,7 +371,8 @@ function getPositivesCount(arr) { * [ 'one','one','one','zero' ] => [ 'zero','one','one','one' ] */ function sortDigitNamesByNumericOrder(arr) { - throw new Error('Not implemented'); + const newArr = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; + return arr.sort((a, b) => newArr.indexOf(a) - newArr.indexOf(b)); } /** @@ -337,7 +388,10 @@ function sortDigitNamesByNumericOrder(arr) { * [ 1, 10, 100, 1000 ] => 1111 */ function getItemsSum(arr) { - throw new Error('Not implemented'); + if (arr.length){ + return arr.reduce((accum, curr) =>accum + curr); + } + return 0; } /** @@ -353,7 +407,15 @@ function getItemsSum(arr) { * [ null, undefined, NaN, false, 0, '' ] => 6 */ function getFalsyValuesCount(arr) { - throw new Error('Not implemented'); + let newArr = []; + if (arr.length){ + arr.map((el) =>{ + if (Boolean(el) === false){ + newArr.push(el); + } + }); + } + return newArr.length; } /** @@ -371,7 +433,13 @@ function getFalsyValuesCount(arr) { * [ true, 0, 1, 'true' ], true => 1 */ function findAllOccurences(arr, item) { - throw new Error('Not implemented'); + let newArr = []; + arr.map ((el) =>{ + if (el === item){ + newArr.push(el); + } + }); + return newArr.length; } /** @@ -386,7 +454,7 @@ function findAllOccurences(arr, item) { * ['rock', 'paper', 'scissors'] => 'rock,paper,scissors' */ function toStringList(arr) { - throw new Error('Not implemented'); + return arr.join(','); } @@ -415,7 +483,18 @@ function toStringList(arr) { * { country: 'Russia', city: 'Saint Petersburg' } */ function sortCitiesArray(arr) { - throw new Error('Not implemented'); + return arr.sort((a, b) => { + if (a.country > b.country) { + return 1 + } + return -1 + }).sort((a, b) => { + if (a.country === b.country && a.city < b.city) { + return 1 + } else { + return -1 + } + }).reverse(); } /** @@ -437,8 +516,8 @@ function sortCitiesArray(arr) { * [0,0,0,0,1]] */ function getIdentityMatrix(n) { - throw new Error('Not implemented'); -} + return Array(n).fill(Array(n).fill()).map((arr, arrIndex) => arr.map((arrEl, elIndex) => arrIndex === elIndex ? 1 : 0)) + } /** * Creates an array of integers from the specified start to end (inclusive) @@ -454,7 +533,19 @@ function getIdentityMatrix(n) { * 3, 3 => [ 3 ] */ function getIntervalArray(start, end) { - throw new Error('Not implemented'); + let arr = new Array(end - start + 1).fill('i') + let element = start; + let newArr = []; + arr.map((el) => { + if (arr.indexOf(el) === 0) { + arr[0] = start; + newArr.push(start); + } else { + element += 1; + newArr.push(element) + } + }); + return newArr; } /** @@ -469,7 +560,14 @@ function getIntervalArray(start, end) { * [ 1, 1, 2, 2, 3, 3, 4, 4] => [ 1, 2, 3, 4] */ function distinct(arr) { - throw new Error('Not implemented'); + let newArr = []; + arr.map((el) =>{ + let i = newArr.find(item => item === el); + if (i === undefined){ + newArr.push(el); + } + }); + return newArr; } /** @@ -503,7 +601,17 @@ function distinct(arr) { * } */ function group(array, keySelector, valueSelector) { - throw new Error('Not implemented'); + let newArr = [] + array.map((el) => { + const doubleEl = newArr.find(item => item[0] === keySelector(el)) + if (doubleEl === undefined) { + newArr.push([keySelector(el)]) + } + }) + return newArr.map((el) => { + el.push(array.filter(item => keySelector(item) === el[0]).map(item => valueSelector(item))) + return el + }) } @@ -519,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'); + let newArr = []; + arr.map((el, index) => { + (childrenSelector(arr[index]).map((item) => { + newArr.push(item) + })) + }) + return newArr; } @@ -536,7 +650,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((prev, curr) => prev[curr], arr) } @@ -559,7 +673,10 @@ function getElementByIndexes(arr, indexes) { * */ function swapHeadAndTail(arr) { - throw new Error('Not implemented'); + const middle = Math.floor(arr.length/2); + const head = arr.splice(0, middle); + const tail = arr.splice(arr.length - middle); + return [...tail, ...arr, ...head]; } From e65be69ca28754f2cd615d6094b1ab1f7cebcc7f Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 16:38:43 +0300 Subject: [PATCH 2/6] Adds correction to getDistanceBetweenPoints function --- task/02-numbers-tasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index aaff3a95f..c9b5ca3cf 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -76,7 +76,7 @@ function getAverage(value1, value2) { * (-5,0) (10,-10) => 18.027756377319946 */ function getDistanceBetweenPoints(x1, y1, x2, y2) { - return Math.sqrt(((x2-x1)**2) +((y2-y1)**2)); + return Math.sqrt(((x2-x1)*(x2-x1)) +((y2-y1)*(y2-y1))); } /** From c8486f9659b2c06210fc14ddc7320531fab7590e Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 16:56:10 +0300 Subject: [PATCH 3/6] Deletes console.logs, corrects functions --- task/01-strings-tasks.js | 3 +-- task/02-numbers-tasks.js | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/task/01-strings-tasks.js b/task/01-strings-tasks.js index 82b6d598a..8dc144aff 100644 --- a/task/01-strings-tasks.js +++ b/task/01-strings-tasks.js @@ -204,8 +204,7 @@ function getRectangleString(width, height) { let top = `┌${'─'.repeat(width -2)}┐\n` ; let side = `│${' '.repeat(width -2)}│\n`; let bottom = `└${'─'.repeat(width -2)}┘\n`; - - console.log(top + side.repeat(height - 2) + bottom) + return top + side.repeat(height - 2) + bottom; } diff --git a/task/02-numbers-tasks.js b/task/02-numbers-tasks.js index c9b5ca3cf..9f5c6df6d 100644 --- a/task/02-numbers-tasks.js +++ b/task/02-numbers-tasks.js @@ -38,7 +38,7 @@ function getRectangleArea(width, height) { * 0 => 0 */ function getCicleCircumference(radius) { - return 2*Math.sqrt*radius; + return 2 * Math.PI * radius; } /** @@ -164,7 +164,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((a*a + b*b) + c*c) } /** @@ -188,7 +188,7 @@ function roundToPowerOfTen(num, pow) { if (pow === 0){ return num; } - return Math.round(num/(10**pow)) * 10**pow; + return Math.round(num/Math.pow(10, pow)) * Math.pow(10, pow); } /** @@ -210,7 +210,6 @@ function roundToPowerOfTen(num, pow) { */ function isPrime(n) { for(let i = 2; i < n; i++) { - console.log(n, i) if(n % i === 0) { return false; } From 731477376669f0207517f9c832ea6050343a3ff8 Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 17:07:52 +0300 Subject: [PATCH 4/6] Corrects function sorting --- task/04-arrays-tasks.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index 374e1c93e..81c87c679 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -484,17 +484,11 @@ function toStringList(arr) { */ function sortCitiesArray(arr) { return arr.sort((a, b) => { - if (a.country > b.country) { - return 1 + if (a.country === b.country) { + return a.city > b.city ? 1 : -1; } - return -1 - }).sort((a, b) => { - if (a.country === b.country && a.city < b.city) { - return 1 - } else { - return -1 - } - }).reverse(); + return a.country > b.country ? 1 : -1 + }); } /** From 70c17f505a51816e9289a769676a9f49e978cf3c Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 17:17:16 +0300 Subject: [PATCH 5/6] adds fix --- task/04-arrays-tasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task/04-arrays-tasks.js b/task/04-arrays-tasks.js index 81c87c679..bb1670da5 100644 --- a/task/04-arrays-tasks.js +++ b/task/04-arrays-tasks.js @@ -333,7 +333,7 @@ function get3TopItems(arr) { /** - * + * Returns the number of positive numbers from specified array * * @param {array} arr * @return {number} From c4383183969e6cd792af9b2811bb42871e9da444 Mon Sep 17 00:00:00 2001 From: Roman Tarasenko Date: Mon, 3 Aug 2020 17:33:54 +0300 Subject: [PATCH 6/6] Adds repo name fixes --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79f9dff75..4ba6d87c7 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/RomanTarasenko/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 @@ -73,7 +73,7 @@ and run the unit tests again. Find one test failed (red). Now it's time to fix i * Implement the function by any way and verify your solution by running tests until the failed test become passed (green). * Your solution work, but now time to refactor it. Try to make your code as pretty and simple as possible keeping up the test green. * Once you can't improve your code and tests are passed you can commit your solution. -* Push your updates to github server and check if tests passed on [travis-ci](https://travis-ci.org/rolling-scopes-school/js-assignments/builds). +* Push your updates to github server and check if tests passed on [travis-ci](https://travis-ci.org/RomanTarasenko/js-assignments/builds). * If everything is OK you can try to resolve the next task. ### How to debug tasks diff --git a/package.json b/package.json index 712b264fa..2acdf682b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,6 @@ }, "repository" : { "type" : "git", - "url" : "https://github.com/rolling-scopes-school/js-assignments.git" + "url" : "https://github.com/RomanTarasenko/js-assignments.git" } }