Skip to content

Test #95

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

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Test #95

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
aff8315
Update the links
Shagoysai Jun 10, 2021
6aa39cf
Update the links
Shagoysai Jun 10, 2021
65b35c5
Update .travis.yml
Shagoysai Jun 10, 2021
d2f1c19
Update .travis.yml
Shagoysai Jun 10, 2021
6ac5d8e
Merge branch 'master' of https://github.com/Shagoysai/js-assignments
Shagoysai Jun 10, 2021
bcf15c4
Task1
Shagoysai Jun 10, 2021
06859df
Task2
Shagoysai Jun 10, 2021
09cddaa
Task3
Shagoysai Jun 10, 2021
4fcff37
Update 04-arrays-tasks.js
Shagoysai Jun 10, 2021
5552fe4
Update 05-regex-tasks.js
Shagoysai Jun 10, 2021
895428a
Update 06-conditions-n-loops-tasks.js
Shagoysai Jun 10, 2021
26a7e3f
Update 07-yield-tasks.js
Shagoysai Jun 10, 2021
788ce68
Update 08-objects-tasks.js
Shagoysai Jun 11, 2021
8a51052
Update 09-functions-n-closures-tasks.js
Shagoysai Jun 11, 2021
aa95469
Update 10-katas-1-tasks.js
Shagoysai Jun 11, 2021
39d8512
Update 01-strings-tasks.js
Shagoysai Jun 11, 2021
0c6010d
Update 02-numbers-tasks.js
Shagoysai Jun 11, 2021
ebc2dc8
Update .travis.yml
Shagoysai Jun 11, 2021
55214d3
Initial commit
Shagoysai Jun 12, 2021
c886aca
Add files via upload
Shagoysai Jun 12, 2021
b01861a
Add files via upload
Shagoysai Jun 12, 2021
4f0c02d
Merge pull request #1 from Shagoysai/second
Shagoysai Jun 12, 2021
9312979
Update .travis.yml
Shagoysai Jun 12, 2021
e21126e
Update 04-arrays-tasks.js
Shagoysai Jun 12, 2021
65eda38
Update 04-arrays-tasks.js
Shagoysai Jun 12, 2021
19f4c53
Update 05-regex-tasks.js
Shagoysai Jun 12, 2021
42dde8a
Update 05-regex-tasks.js
Shagoysai Jun 12, 2021
155cb47
Update 06-conditions-n-loops-tasks.js
Shagoysai Jun 12, 2021
b51537e
Update 07-yield-tasks.js
Shagoysai Jun 12, 2021
b1b9462
Update 08-objects-tasks.js
Shagoysai Jun 12, 2021
50f9ee9
Update 09-functions-n-closures-tasks.js
Shagoysai Jun 12, 2021
7bd172c
Update 02-numbers-tasks.js
Shagoysai Jun 12, 2021
bd56f13
Update 06-conditions-n-loops-tasks.js
Shagoysai Jun 12, 2021
25c5494
Update 06-conditions-n-loops-tests.js
Shagoysai Jun 12, 2021
cbdb6c0
Update 06-conditions-n-loops-tasks.js
Shagoysai Jun 12, 2021
41a51c8
Update 02-numbers-tasks.js
Shagoysai Jun 14, 2021
30dd482
Update 04-arrays-tasks.js
Shagoysai Jun 14, 2021
716f7c4
Update 06-conditions-n-loops-tasks.js
Shagoysai Jun 14, 2021
f73f1d3
Update 07-yield-tasks.js
Shagoysai Jun 14, 2021
b56b855
Update 08-objects-tasks.js
Shagoysai Jun 14, 2021
5e971e3
Update 09-functions-n-closures-tasks.js
Shagoysai Jun 14, 2021
034f0ef
Update 08-objects-tasks.js
Shagoysai Jun 14, 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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
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.17.0"
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Brest Rolling Scopes](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/rolling-scopes-school/js-assignments.svg?branch=master)](https://travis-ci.org/rolling-scopes-school/js-assignments)
[![Brest Shagoysai](http://brest.rollingscopes.com/images/logo_rs_text.svg)](http://brest.rollingscopes.com/)
#Brest Shagoysai School
## Javascript Assignments [![Build Status](https://travis-ci.org/Shagoysai/js-assignments.svg?branch=master)](https://travis-ci.org/Shagoysai/js-assignments)

Yet another javascript assignments. There are a lot of interactive javascript resources for beginners, but most of them are online and do not cover the modern programming workflow. There are some excellent training resources on github (https://github.com/rmurphey/js-assessment, https://github.com/mrdavidlaing/javascript-koans, https://github.com/vasanthk/js-bits etc) but they are not exactly simulate the everyday programming process. So the motivation of this project is to show TDD process in the wild to the beginners. Assingment tests are implemented in various ways to feel a difference and gain the experience what manner is good, what is bad and what is ugly.

Expand All @@ -22,14 +22,14 @@ To start javascript assignments please follow the next steps:
### How to setup travis-ci
* Open [https://travis-ci.org/](https://travis-ci.org/) and sign in with your github account.
* Activate your forked repo **js-assignments**.
* Edit local README.md file and update all links (just replace all occurrences of `'rolling-scopes-school'` with your account name).
* Edit local README.md file and update all links (just replace all occurrences of `'Shagoysai'` with your account name).
* Commit and push updated README.md to github:
```bash
git add README.md
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/Shagoysai/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/Shagoysai/js-assignments/builds).
* If everything is OK you can try to resolve the next task.

### How to debug tasks
Expand Down
43 changes: 28 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.concat(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 new RegExp("Hello, (.+)!").exec(value)[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('<', '').replace('>', '');
}


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

/**
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,10 @@ function extractEmails(str) {
*
*/
function getRectangleString(width, height) {
throw new Error('Not implemented');
const top = `┌${'─'.repeat(width - 2)}┐\n`;
const mid = `│${' '.repeat(width - 2)}│\n`;
const bottom = `└${'─'.repeat(width - 2)}┘\n`;
return top + mid.repeat(height - 2) + bottom;
}


Expand All @@ -221,7 +224,10 @@ function getRectangleString(width, height) {
*
*/
function encodeToRot13(str) {
throw new Error('Not implemented');
const input = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
const output = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'.split('');
const lookup = input.reduce((m, k, i) => Object.assign(m, { [k]: output[i] }), {});
return str.split('').map((x) => lookup[x] || x).join('');
}

/**
Expand All @@ -238,7 +244,7 @@ function encodeToRot13(str) {
* isString(new String('test')) => true
*/
function isString(value) {
throw new Error('Not implemented');
return Object.prototype.toString.call(value) === "[object String]";
}


Expand Down Expand Up @@ -267,7 +273,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
36 changes: 24 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 Math.PI * radius * 2;
}

/**
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,9 @@ function getAverage(value1, value2) {
* (-5,0) (10,-10) => 18.027756377319946
*/
function getDistanceBetweenPoints(x1, y1, x2, y2) {
throw new Error('Not implemented');
var a = x1 - x2;
var b = y1 - y2;
return Math.sqrt(a*a + b*b);
}

/**
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 -1 * 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');
var angle = Math.atan2(y2, x2) - Math.atan2(y1, x1)
if (angle < 0) {
angle += 2 * Math.PI;
}
return angle
}

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


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

/**
Expand All @@ -160,7 +166,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 @@ -181,7 +187,9 @@ function getParallelipidedDiagonal(a,b,c) {
* 1678, 3 => 2000
*/
function roundToPowerOfTen(num, pow) {
throw new Error('Not implemented');
let a = Math.pow(10, pow);

return (a === 0) ? num : Math.round(num / a) * a;
}

/**
Expand All @@ -202,7 +210,11 @@ function roundToPowerOfTen(num, pow) {
* 17 => true
*/
function isPrime(n) {
throw new Error('Not implemented');
for (let i = 2; i < n / 2 + 1; i++) {
if (n % i == 0)
return false;
}
return true;
}

/**
Expand All @@ -221,7 +233,7 @@ function isPrime(n) {
* toNumber(new Number(42), 0) => 42
*/
function toNumber(value, def) {
throw new Error('Not implemented');
return typeof +value == 'number' && !isNaN(+value) ? +value : def;
}

module.exports = {
Expand Down
17 changes: 12 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,8 @@ function parseDataFromIso8601(value) {
* Date(2015,1,1) => false
*/
function isLeapYear(date) {
throw new Error('Not implemented');
const year = date.getFullYear();
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
}


Expand All @@ -76,7 +77,7 @@ 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);
}


Expand All @@ -94,7 +95,13 @@ function timeSpanToString(startDate, endDate) {
* Date.UTC(2016,3,5,21, 0) => Math.PI/2
*/
function angleBetweenClockHands(date) {
throw new Error('Not implemented');
const hoursArrow = 0.5 * (60 * (date.getUTCHours() % 12) + date.getUTCMinutes());
const minutesArrow = 6 * date.getUTCMinutes();
let angle = Math.abs(hoursArrow - minutesArrow);
if (angle > 180) {
angle = 360 - angle;
}
return (angle * Math.PI / 180);
}


Expand Down
Loading