Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
53 changes: 37 additions & 16 deletions task/01-strings-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* '', 'bb' => 'bb'
*/
function concatenateStrings(value1, value2) {
throw new Error('Not implemented');
return value1+value2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, try to follow these rules https://javascript.info/coding-style
spaces between operators

}


Expand All @@ -38,7 +38,7 @@ function concatenateStrings(value1, value2) {
* '' => 0
*/
function getStringLength(value) {
throw new Error('Not implemented');
return value.length;
}

/**
Expand All @@ -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}!`;
}

/**
Expand All @@ -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);
}


Expand All @@ -84,7 +84,7 @@ function extractNameFromTemplate(value) {
* 'cat' => 'c'
*/
function getFirstChar(value) {
throw new Error('Not implemented');
return value.substring(0,1);
}

/**
Expand All @@ -99,7 +99,7 @@ function getFirstChar(value) {
* '\tHello, World! ' => 'Hello, World!'
*/
function removeLeadingAndTrailingWhitespaces(value) {
throw new Error('Not implemented');
return value.trim();
}

/**
Expand All @@ -114,7 +114,7 @@ function removeLeadingAndTrailingWhitespaces(value) {
* 'cat', 3 => 'catcatcat'
*/
function repeatString(value, count) {
throw new Error('Not implemented');
return value.repeat(count);
}

/**
Expand All @@ -130,7 +130,7 @@ function repeatString(value, count) {
* 'ABABAB','BA' => 'ABAB'
*/
function removeFirstOccurrences(str, value) {
throw new Error('Not implemented');
return str.replace(value, "");
}

/**
Expand All @@ -145,7 +145,7 @@ function removeFirstOccurrences(str, value) {
* '<a>' => 'a'
*/
function unbracketTag(str) {
throw new Error('Not implemented');
return str.replace(/[\<\>]+/g, "");
}


Expand All @@ -160,7 +160,7 @@ function unbracketTag(str) {
* 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
*/
function convertToUpperCase(str) {
throw new Error('Not implemented');
return str.toLocaleUpperCase();
}

/**
Expand All @@ -174,7 +174,7 @@ function convertToUpperCase(str) {
* '[email protected]' => ['[email protected]']
*/
function extractEmails(str) {
throw new Error('Not implemented');
return str.split(";") ;
}

/**
Expand All @@ -201,7 +201,11 @@ 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`;

return top + side.repeat(height - 2) + bottom;
}


Expand All @@ -221,7 +225,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('');
}

/**
Expand All @@ -238,7 +246,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')
}


Expand Down Expand Up @@ -267,9 +282,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,
Expand Down
39 changes: 27 additions & 12 deletions task/02-numbers-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* 5, 5 => 25
*/
function getRectangleArea(width, height) {
throw new Error('Not implemented');
return width * height;
}


Expand All @@ -38,7 +38,7 @@ function getRectangleArea(width, height) {
* 0 => 0
*/
function getCicleCircumference(radius) {
throw new Error('Not implemented');
return 2 * Math.PI * radius;
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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)*(x2-x1)) +((y2-y1)*(y2-y1)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to improve using Math.hypot

}

/**
Expand All @@ -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);
}


Expand All @@ -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))
}

/**
Expand All @@ -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;
}


Expand All @@ -143,7 +147,7 @@ function getLastDigit(value) {
* '-525.5' => -525.5
*/
function parseNumberFromString(value) {
throw new Error('Not implemented');
return +value
}

/**
Expand All @@ -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*a + b*b) + c*c)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to improve using Math.hypot

}

/**
Expand All @@ -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/Math.pow(10, pow)) * Math.pow(10, pow);
}

/**
Expand All @@ -202,7 +209,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 n > 1;
}

/**
Expand All @@ -221,7 +233,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 = {
Expand Down
40 changes: 35 additions & 5 deletions task/03-date-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;
}

/**
Expand All @@ -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);
}


Expand All @@ -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;

}


Expand All @@ -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}`;
}


Expand All @@ -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;
}


Expand Down
Loading