-
Notifications
You must be signed in to change notification settings - Fork 192
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-4 Tasks. Alexey_Karavaychik #824
base: master
Are you sure you want to change the base?
Changes from all commits
169c9ad
2149124
d14155f
d3edd92
1af98a0
3ab90ae
d90f276
011d553
f1f1be2
b16c4ff
f8423ca
1eb8150
c0dc4c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "5.10.0" | ||
- "12.18.2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
/******************************************************************************************** | ||
* * | ||
* Plese read the following tutorial before implementing tasks: * | ||
* Please read the following tutorial before implementing tasks: * | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String * | ||
* * | ||
********************************************************************************************/ | ||
|
@@ -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+"!") | ||
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. |
||
} | ||
|
||
/** | ||
|
@@ -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[0] | ||
} | ||
|
||
/** | ||
|
@@ -99,7 +99,13 @@ function getFirstChar(value) { | |
* '\tHello, World! ' => 'Hello, World!' | ||
*/ | ||
function removeLeadingAndTrailingWhitespaces(value) { | ||
throw new Error('Not implemented'); | ||
while (value[0] === (" ") || value[0] === ("\t")) { | ||
value = (value[0] === (" ") || value[0] === ("\t") ? value.substring(1) : value) | ||
} | ||
while (value[value.length-1] === (" ") || value[value.length-1] === ("\t")) { | ||
value = (value[value.length-1] === (" ") || value[value.length-1] === ("\t") ? value.substring(0,value.length-1) : value) | ||
} | ||
return value | ||
Comment on lines
+102
to
+108
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. |
||
} | ||
|
||
/** | ||
|
@@ -114,7 +120,7 @@ function removeLeadingAndTrailingWhitespaces(value) { | |
* 'cat', 3 => 'catcatcat' | ||
*/ | ||
function repeatString(value, count) { | ||
throw new Error('Not implemented'); | ||
return value.repeat(count) | ||
} | ||
|
||
/** | ||
|
@@ -130,7 +136,8 @@ function repeatString(value, count) { | |
* 'ABABAB','BA' => 'ABAB' | ||
*/ | ||
function removeFirstOccurrences(str, value) { | ||
throw new Error('Not implemented'); | ||
let pos = str.indexOf(value) | ||
return str.substring(0,pos)+str.substring(pos+value.length,str.length) | ||
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. |
||
} | ||
|
||
/** | ||
|
@@ -145,7 +152,7 @@ function removeFirstOccurrences(str, value) { | |
* '<a>' => 'a' | ||
*/ | ||
function unbracketTag(str) { | ||
throw new Error('Not implemented'); | ||
return str.substring(1,str.length-1) | ||
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. space between parameters |
||
} | ||
|
||
|
||
|
@@ -160,7 +167,7 @@ function unbracketTag(str) { | |
* 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
*/ | ||
function convertToUpperCase(str) { | ||
throw new Error('Not implemented'); | ||
return str.toUpperCase() | ||
} | ||
|
||
/** | ||
|
@@ -174,7 +181,9 @@ function convertToUpperCase(str) { | |
* '[email protected]' => ['[email protected]'] | ||
*/ | ||
function extractEmails(str) { | ||
throw new Error('Not implemented'); | ||
let newArrayOfStr = str.split(";") | ||
newArrayOfStr.forEach((el) => ("'"+el+"'")) | ||
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. This line is unnecessary. It hasn't any impact on the result, because it doesn't mutate initial array and returns https://stackoverflow.com/questions/34426458/javascript-difference-between-foreach-and-map |
||
return newArrayOfStr | ||
} | ||
|
||
/** | ||
|
@@ -201,7 +210,20 @@ function extractEmails(str) { | |
* | ||
*/ | ||
function getRectangleString(width, height) { | ||
throw new Error('Not implemented'); | ||
let str = "" | ||
for (let h=1;h<=height;h++) { | ||
for (let w=1; w<=width; w++) { | ||
((h===1)&&(w===1)) && (str+="┌"); | ||
(((h===1)||(h===height)) && (w!==1 && w!==width) && (str+="─")); | ||
((h===1)&&(w===width)) && (str+="┐\n"); | ||
(w===1) && (h!==1 && h!==height) && (str+="│"); | ||
(w===width) && (h!==1 && h!==height) && (str+="│\n"); | ||
(h>1 && h<height)&&(w>1 && w<width) && (str+=" "); | ||
(w===1) && (h===height) && (str+="└"); | ||
(w===width)&&(h===height) && (str+="┘\n") | ||
Comment on lines
+213
to
+223
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. Spaces around operators |
||
} | ||
} | ||
return str | ||
} | ||
|
||
|
||
|
@@ -221,7 +243,18 @@ function getRectangleString(width, height) { | |
* | ||
*/ | ||
function encodeToRot13(str) { | ||
throw new Error('Not implemented'); | ||
let newStr = str.split(""); | ||
let alphabetLowerCase = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; | ||
let alphabetUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
for (let i=0; i<str.length; i++) { | ||
if (alphabetUpperCase.includes(newStr[i])) { | ||
newStr[i]=alphabetUpperCase[alphabetUpperCase.indexOf(str[i])+13] | ||
} | ||
if (alphabetLowerCase.includes(newStr[i])) { | ||
newStr[i]=alphabetLowerCase[alphabetLowerCase.indexOf(str[i])+13] | ||
} | ||
} | ||
return newStr.toString().split(",").join("") | ||
} | ||
|
||
/** | ||
|
@@ -238,7 +271,8 @@ function encodeToRot13(str) { | |
* isString(new String('test')) => true | ||
*/ | ||
function isString(value) { | ||
throw new Error('Not implemented'); | ||
if (value instanceof String) return true | ||
return (typeof(value)==="string") | ||
} | ||
|
||
|
||
|
@@ -267,7 +301,9 @@ function isString(value) { | |
* 'K♠' => 51 | ||
*/ | ||
function getCardId(value) { | ||
throw new Error('Not implemented'); | ||
let cardSuit = "♣♦♥♠"; | ||
let cardValue = "A234567891JQK"; | ||
return cardSuit.indexOf(value[value.length-1])*13+cardValue.indexOf(value[0]); | ||
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. space around operators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators |
||
} | ||
|
||
|
||
|
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,7 @@ function getCicleCircumference(radius) { | |
* -3, 3 => 0 | ||
*/ | ||
function getAverage(value1, value2) { | ||
throw new Error('Not implemented'); | ||
return (value1/2+value2/2) | ||
} | ||
|
||
/** | ||
|
@@ -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.sqrt((x2-x1)**2+(y2-y1)**2) | ||
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. Please, improve using Math.hypot |
||
} | ||
|
||
/** | ||
|
@@ -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===0 ? b/a : -b/a | ||
} | ||
|
||
|
||
|
@@ -111,7 +111,7 @@ 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**2+y1**2)*(Math.sqrt(x2**2+y2**2)))) | ||
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. Please, improve using Math.hypot |
||
} | ||
|
||
/** | ||
|
@@ -127,7 +127,7 @@ function getAngleBetweenVectors(x1, y1, x2, y2) { | |
* 0 => 0 | ||
*/ | ||
function getLastDigit(value) { | ||
throw new Error('Not implemented'); | ||
return value%10 | ||
} | ||
|
||
|
||
|
@@ -143,7 +143,7 @@ function getLastDigit(value) { | |
* '-525.5' => -525.5 | ||
*/ | ||
function parseNumberFromString(value) { | ||
throw new Error('Not implemented'); | ||
return +value | ||
} | ||
|
||
/** | ||
|
@@ -160,7 +160,7 @@ function parseNumberFromString(value) { | |
* 1,2,3 => 3.741657386773941 | ||
*/ | ||
function getParallelipidedDiagonal(a,b,c) { | ||
throw new Error('Not implemented'); | ||
return Math.sqrt(a**2+b**2+c**2) | ||
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. Please, improve using Math.hypot |
||
} | ||
|
||
/** | ||
|
@@ -181,7 +181,7 @@ function getParallelipidedDiagonal(a,b,c) { | |
* 1678, 3 => 2000 | ||
*/ | ||
function roundToPowerOfTen(num, pow) { | ||
throw new Error('Not implemented'); | ||
return Math.round(num*0.1**pow)*(10**pow) | ||
} | ||
|
||
/** | ||
|
@@ -202,7 +202,8 @@ function roundToPowerOfTen(num, pow) { | |
* 17 => true | ||
*/ | ||
function isPrime(n) { | ||
throw new Error('Not implemented'); | ||
for (let i=2; i<n-1;i++) if (n%i===0) return false | ||
return true | ||
} | ||
|
||
/** | ||
|
@@ -221,7 +222,8 @@ function isPrime(n) { | |
* toNumber(new Number(42), 0) => 42 | ||
*/ | ||
function toNumber(value, def) { | ||
throw new Error('Not implemented'); | ||
if (+value) return +value; | ||
return def; | ||
} | ||
|
||
module.exports = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
|
||
/** | ||
|
@@ -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) | ||
} | ||
|
||
|
||
|
@@ -56,7 +56,8 @@ function parseDataFromIso8601(value) { | |
* Date(2015,1,1) => false | ||
*/ | ||
function isLeapYear(date) { | ||
throw new Error('Not implemented'); | ||
let year = new Date(date).getFullYear(); | ||
return (year%4===0)&&((year%100!==0)||(year%400===0)) | ||
} | ||
|
||
|
||
|
@@ -76,7 +77,12 @@ 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 date = new Date(endDate.getTime() - startDate.getTime()); | ||
let days = endDate.getDay()- startDate.getDay(); | ||
return ""+((date.getUTCHours()+24*days)<10 ? "0"+date.getUTCHours() : date.getUTCHours()+24*days)+":" | ||
+(date.getUTCMinutes()<10 ? "0"+date.getUTCMinutes() : date.getUTCMinutes())+":" | ||
+(date.getUTCSeconds()<10 ? "0"+date.getUTCSeconds() : date.getUTCSeconds())+"." | ||
+(date.getUTCMilliseconds()<100 ? (date.getUTCMilliseconds()<10 ? "00"+date.getUTCMilliseconds() : "0"+date.getUTCMilliseconds()) : date.getUTCMilliseconds()) | ||
Comment on lines
+82
to
+85
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. Please, avoid this code style, if-else is more readable than multiple conditional operators ? : And space around operators |
||
} | ||
|
||
|
||
|
@@ -94,7 +100,11 @@ function timeSpanToString(startDate, endDate) { | |
* Date.UTC(2016,3,5,21, 0) => Math.PI/2 | ||
*/ | ||
function angleBetweenClockHands(date) { | ||
throw new Error('Not implemented'); | ||
let hoursDegrees = (date.getUTCHours()>=12) ? date.getUTCHours()%12 : date.getUTCHours(); | ||
hoursDegrees = Math.abs(0.5*(60*hoursDegrees-11*date.getUTCMinutes())) | ||
if (hoursDegrees>180) hoursDegrees=360-hoursDegrees | ||
let degrees = hoursDegrees*(Math.PI/180) | ||
return degrees | ||
} | ||
|
||
|
||
|
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.
spaces around operators
Please, try to follow these rules https://javascript.info/coding-style