Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Невоструев ИПР1-2 #94

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e651e3b
Task1
Taras2201 May 30, 2021
0110568
Task3
Taras2201 May 30, 2021
3a19aa9
Task2
Taras2201 May 30, 2021
e65bb9f
Task4
Taras2201 May 30, 2021
98724f5
Task6
Taras2201 May 31, 2021
42ae234
Task5
Taras2201 May 31, 2021
563a969
Task4
Taras2201 May 31, 2021
fa7ce11
Task2
Taras2201 May 31, 2021
f497590
Task7
Taras2201 May 31, 2021
0e94e2d
Task8
Taras2201 May 31, 2021
fde44ac
Task9
Taras2201 May 31, 2021
d69ad27
Task10
Taras2201 May 31, 2021
fce5db1
Task11
Taras2201 May 31, 2021
537df6e
Task12
Taras2201 May 31, 2021
26a1e40
Task6
Taras2201 May 31, 2021
941d569
Task5
Taras2201 May 31, 2021
494ef06
Task3
Taras2201 May 31, 2021
abfc6fb
Task1
Taras2201 May 31, 2021
1816927
Task2
Taras2201 May 31, 2021
4380f24
Task2
Taras2201 May 31, 2021
152e4fb
Task4
Taras2201 May 31, 2021
92bc34a
Task4
Taras2201 May 31, 2021
207f049
Task7
Taras2201 May 31, 2021
6d1ecc3
Task8
Taras2201 May 31, 2021
4dd7008
Task9
Taras2201 May 31, 2021
8dea60c
Task10
Taras2201 May 31, 2021
873577b
Task11
Taras2201 May 31, 2021
f925320
Task12
Taras2201 May 31, 2021
6e59569
Tests1
Taras2201 May 31, 2021
6bd80a9
Tests2
Taras2201 May 31, 2021
59acfa8
Tests3
Taras2201 May 31, 2021
1e614f3
Tests4
Taras2201 May 31, 2021
b441c94
Tests5
Taras2201 May 31, 2021
a53fc10
Tests6
Taras2201 May 31, 2021
8cfc4d2
Tests7
Taras2201 May 31, 2021
2b55b7e
Tests8
Taras2201 May 31, 2021
28186ff
Tests9
Taras2201 May 31, 2021
8f5ff19
Tests10
Taras2201 May 31, 2021
f649b61
Tests11
Taras2201 May 31, 2021
0bdcf11
Tests12
Taras2201 May 31, 2021
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
44 changes: 28 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 ;
}


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,10 +69,9 @@ function getStringFromTemplate(firstName, lastName) {
* 'Hello, Chuck Norris!' => 'Chuck Norris'
*/
function extractNameFromTemplate(value) {
throw new Error('Not implemented');
return value.slice(7, -1);
}


/**
* Returns a first char of the given string.
*
Expand All @@ -84,7 +83,7 @@ function extractNameFromTemplate(value) {
* 'cat' => 'c'
*/
function getFirstChar(value) {
throw new Error('Not implemented');
return value[0];
}

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

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

/**
Expand All @@ -130,7 +129,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 +144,7 @@ function removeFirstOccurrences(str, value) {
* '<a>' => 'a'
*/
function unbracketTag(str) {
throw new Error('Not implemented');
return str.slice(1, str.length-1);
}


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

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

/**
Expand All @@ -201,7 +200,9 @@ 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';
}


Expand All @@ -221,7 +222,11 @@ function getRectangleString(width, height) {
*
*/
function encodeToRot13(str) {
throw new Error('Not implemented');
var input = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var output = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
var index = x => input.indexOf(x);
var translate = x => index(x) > -1 ? output[index(x)] : x;
return str.split('').map(translate).join('');
}

/**
Expand All @@ -238,7 +243,7 @@ function encodeToRot13(str) {
* isString(new String('test')) => true
*/
function isString(value) {
throw new Error('Not implemented');
return typeof value === 'string' || value instanceof String;
}


Expand Down Expand Up @@ -267,7 +272,14 @@ 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);
}


Expand Down
45 changes: 31 additions & 14 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,7 @@ function getCicleCircumference(radius) {
* -3, 3 => 0
*/
function getAverage(value1, value2) {
throw new Error('Not implemented');
return value1 / 2 + value2 / 2;
}

/**
Expand All @@ -73,7 +73,7 @@ function getAverage(value1, value2) {
* (-5,0) (10,-10) => 18.027756377319946
*/
function getDistanceBetweenPoints(x1, y1, x2, y2) {
throw new Error('Not implemented');
return Math.hypot((x2 - x1), (y2 - y1));
}

/**
Expand All @@ -89,7 +89,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 +111,9 @@ 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(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2))
);
}

/**
Expand All @@ -127,7 +129,7 @@ function getAngleBetweenVectors(x1, y1, x2, y2) {
* 0 => 0
*/
function getLastDigit(value) {
throw new Error('Not implemented');
return value % 10;
}


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

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

/**
Expand All @@ -169,7 +171,7 @@ function getParallelipidedDiagonal(a,b,c) {
* @param {number} num
* @param {number} pow
* @return {number}
*
*
* @example:
* 1234, 0 => 1234
* 1234, 1 => 1230
Expand All @@ -181,7 +183,7 @@ function getParallelipidedDiagonal(a,b,c) {
* 1678, 3 => 2000
*/
function roundToPowerOfTen(num, pow) {
throw new Error('Not implemented');
return Math.round(num / Math.pow(10, pow)) * Math.pow(10, pow);
}

/**
Expand All @@ -190,7 +192,7 @@ function roundToPowerOfTen(num, pow) {
*
* @param {number} n
* @return {bool}
*
*
* @example:
* 4 => false
* 5 => true
Expand All @@ -202,7 +204,22 @@ function roundToPowerOfTen(num, pow) {
* 17 => true
*/
function isPrime(n) {
throw new Error('Not implemented');
if (n <= 1) {
return false;
} else if (n <= 3) {
return true;
} else if (!(n % 2) || !(n % 3)) {
return false;
}

let i = 5;
while (i * i <= n) {
if (!(n % i) || !(n % (i + 2))) {
return false;
}
i += 6;
}
return true;
}

/**
Expand All @@ -221,7 +238,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 = {
Expand Down
21 changes: 15 additions & 6 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 new Date(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 new Date(value);
}


Expand All @@ -56,7 +56,9 @@ function parseDataFromIso8601(value) {
* Date(2015,1,1) => false
*/
function isLeapYear(date) {
throw new Error('Not implemented');
if ((date.getFullYear() % 4 == 0 && (date.getFullYear() % 100 != 0)) || date.getFullYear() % 400 == 0)
return true;
return false;
}


Expand All @@ -76,14 +78,14 @@ 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');
return (new Date(endDate - startDate)).toISOString().slice(11, -1);
}


/**
* Returns the angle (in radians) between the hands of an analog clock for the specified Greenwich time.
* If you have problem with solution please read: https://en.wikipedia.org/wiki/Clock_angle_problem
*
*
* @param {date} date
* @return {number}
*
Expand All @@ -94,7 +96,14 @@ function timeSpanToString(startDate, endDate) {
* Date.UTC(2016,3,5,21, 0) => Math.PI/2
*/
function angleBetweenClockHands(date) {
throw new Error('Not implemented');
let h = new Date(date).getUTCHours();
h = h % 12;
let min = new Date(date).getUTCMinutes();
let angle = Math.abs(1/2 * (60 * h - 11 * min));
if (angle > 180) {
angle = (360 - angle);
}
return angle / 180 * Math.PI;
}


Expand Down
Loading