forked from rolling-scopes-school/js-assignments
-
Notifications
You must be signed in to change notification settings - Fork 188
#1-4 Task. Roman Tarasenko #845
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
Draft
RomanTarasenko
wants to merge
6
commits into
AisBrestEDU:master
Choose a base branch
from
RomanTarasenko:files-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72e69c2
Adds 1-4 tasks solutions
RomanTarasenko e65be69
Adds correction to getDistanceBetweenPoints function
RomanTarasenko c8486f9
Deletes console.logs, corrects functions
RomanTarasenko 7314773
Corrects function sorting
RomanTarasenko 70c17f5
adds fix
RomanTarasenko c438318
Adds repo name fixes
RomanTarasenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>' => '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) { | |
* '[email protected]' => ['[email protected]'] | ||
*/ | ||
function extractEmails(str) { | ||
throw new Error('Not implemented'); | ||
return str.split(";") ; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
|
||
|
||
|
@@ -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(''); | ||
} | ||
|
||
/** | ||
|
@@ -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') | ||
} | ||
|
||
|
||
|
@@ -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, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.PI * 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)*(x2-x1)) +((y2-y1)*(y2-y1))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to improve using Math.hypot |
||
} | ||
|
||
/** | ||
|
@@ -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*a + b*b) + c*c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to improve using Math.hypot |
||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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 = { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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