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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "5.10.0"
- "14.5.0"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Brest Rolling Scopes](http://brest.rollingscopes.com/images/logo_rs_text.svg)](http://brest.rollingscopes.com/)
[![NicholasDemidovich](http://brest.rollingscopes.com/images/logo_rs_text.svg)](http://brest.rollingscopes.com/)
#Brest Rolling Scopes School
## Javascript Assignments [![Build Status](https://travis-ci.org/AisBrestEDU/js-assignments.svg?branch=master)](https://travis-ci.org/AisBrestEDU/js-assignments)

Expand Down
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"
}
}
100 changes: 85 additions & 15 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,7 +69,7 @@ function getStringFromTemplate(firstName, lastName) {
* 'Hello, Chuck Norris!' => 'Chuck Norris'
*/
function extractNameFromTemplate(value) {
throw new Error('Not implemented');
return value.slice(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.slice(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,12 @@ function removeLeadingAndTrailingWhitespaces(value) {
* 'cat', 3 => 'catcatcat'
*/
function repeatString(value, count) {
throw new Error('Not implemented');
let tmp="";
for (let i = 0; i < count; i++)
{
tmp += value;
}
return tmp;
}

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


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

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

/**
Expand All @@ -201,7 +207,29 @@ function extractEmails(str) {
*
*/
function getRectangleString(width, height) {
throw new Error('Not implemented');
let strRect="";
let counter=0;
for (let wdth = 0; wdth < width; wdth++){
if (wdth === 0) strRect += '┌';
if (wdth === width - 1) { strRect += '┐\n'; }
else if (wdth < width - 2) strRect += '─';
}
if (height > 2) {
while (counter <= height-3) {
for (let hght = 0; hght < width; hght++) {
if (hght === 0) strRect += '│';
if (hght === width - 1) strRect += '│\n';
else if (hght < width - 2) strRect += ' ';
}
counter++;
}
}
for (let wdth = 0; wdth < width; wdth++) {
if (wdth === 0) strRect += '└';
if (wdth === width - 1) { strRect += '┘\n'; }
else if (wdth < width - 2) strRect += '─';
}
return strRect;
}


Expand All @@ -221,7 +249,35 @@ function getRectangleString(width, height) {
*
*/
function encodeToRot13(str) {
throw new Error('Not implemented');
let arr_en = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
let end_sring = "";
for (let symb = 0; symb < str.length; symb++) {
if (arr_en.includes(str[symb].toLowerCase()) === true) {
if (str[symb] === str[symb].toUpperCase()) {
if (arr_en.indexOf(str[symb].toLowerCase()) + 13 >= 26) {
end_sring += arr_en[arr_en.indexOf(str[symb].toLowerCase()) - 13].toUpperCase();
}
else {
end_sring += arr_en[arr_en.indexOf(str[symb].toLowerCase()) + 13].toUpperCase();
}
}
else if (arr_en.indexOf(str[symb]) + 13 >= 26) {
end_sring += arr_en[arr_en.indexOf(str[symb]) - 13];
}
else {
end_sring += arr_en[arr_en.indexOf(str[symb]) + 13];
}
}
else if (str[symb] === " ") {
end_sring += " ";
}
else {
end_sring += str[symb];
}

}
return end_sring;

}

/**
Expand All @@ -238,9 +294,15 @@ function encodeToRot13(str) {
* isString(new String('test')) => true
*/
function isString(value) {
throw new Error('Not implemented');
if (type(value) === 'string') return true;
return false;
}

function type(value) {
let regex = /^\[object (\S+?)\]$/;
let matches = Object.prototype.toString.call(value).match(regex) || [];
return (matches[1] || 'undefined').toLowerCase();
}

/**
* Returns playid card id.
Expand All @@ -267,7 +329,15 @@ function isString(value) {
* 'K♠' => 51
*/
function getCardId(value) {
throw new Error('Not implemented');
let arr_card = ['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♠'];
let tmp=0;
for (let i = 0; i < 52; i++) {
if (value === arr_card[i]) tmp = i;
}
return tmp;
}


Expand Down
46 changes: 33 additions & 13 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,9 @@ function getRectangleArea(width, height) {
* 0 => 0
*/
function getCicleCircumference(radius) {
throw new Error('Not implemented');
let tmp;
tmp = (2 * Math.PI * radius);
return tmp;
}

/**
Expand All @@ -54,7 +56,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 +75,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(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2))
}

/**
Expand All @@ -89,7 +91,7 @@ function getDistanceBetweenPoints(x1, y1, x2, y2) {
* 5*x = 0 => 0
*/
function getLinearEquationRoot(a, b) {
throw new Error('Not implemented');
return (0 - b) / a;
}


Expand All @@ -111,7 +113,11 @@ function getLinearEquationRoot(a, b) {
* (0,1) (1,2) => 0
*/
function getAngleBetweenVectors(x1, y1, x2, y2) {
throw new Error('Not implemented');
let sklr = x1 * x2 + y1 * y2;
let len_vect1 = Math.abs(x1 + y1);
let len_vect2 = Math.abs(x2 + y2);
let result = Math.acos(sklr / (len_vect1 * len_vect2));
return result;
}

/**
Expand All @@ -127,7 +133,8 @@ function getAngleBetweenVectors(x1, y1, x2, y2) {
* 0 => 0
*/
function getLastDigit(value) {
throw new Error('Not implemented');
let result = value.toString().slice(-1);
return parseInt(result);
}


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

/**
Expand All @@ -159,8 +167,8 @@ function parseNumberFromString(value) {
* 3,3,3 => 5.196152422706632
* 1,2,3 => 3.741657386773941
*/
function getParallelipidedDiagonal(a,b,c) {
throw new Error('Not implemented');
function getParallelipidedDiagonal(a, b, c) {
return Math.sqrt(a * a + b * b + c * c);
}

/**
Expand All @@ -181,7 +189,10 @@ function getParallelipidedDiagonal(a,b,c) {
* 1678, 3 => 2000
*/
function roundToPowerOfTen(num, pow) {
throw new Error('Not implemented');
if (pow === 0) return num;
if (pow === 1) return Math.round(num / 10) * 10;
if (pow === 2) return Math.round(num / 100) * 100;
if (pow === 3) return Math.round(num / 1000) * 1000;
}

/**
Expand All @@ -202,7 +213,14 @@ function roundToPowerOfTen(num, pow) {
* 17 => true
*/
function isPrime(n) {
throw new Error('Not implemented');
let counter = 2;
let limit = Math.sqrt(n);
if (n === 2) return true;
while (counter <= limit) {
if (n % counter === 0) return false;
counter++;
}
return true;
}

/**
Expand All @@ -221,7 +239,9 @@ function isPrime(n) {
* toNumber(new Number(42), 0) => 42
*/
function toNumber(value, def) {
throw new Error('Not implemented');
let result = parseFloat(value, 10);
if (isNaN(result) === true) return def;
return result;
}

module.exports = {
Expand Down
Loading