Skip to content
Open
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
Empty file added 'The
Empty file.
Empty file added -1
Empty file.
Empty file added 0
Empty file.
Empty file added 1
Empty file.
Empty file added 5
Empty file.
Empty file added npx
Empty file.
220 changes: 220 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 48 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[0];
}

/**
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,9 @@ function removeLeadingAndTrailingWhitespaces(value) {
* 'cat', 3 => 'catcatcat'
*/
function repeatString(value, count) {
throw new Error('Not implemented');
let result="";
for (let i=1;i<=count;i++) result=result+value;
return result;
}

/**
Expand All @@ -130,7 +132,9 @@ function repeatString(value, count) {
* 'ABABAB','BA' => 'ABAB'
*/
function removeFirstOccurrences(str, value) {
throw new Error('Not implemented');
let pos=str.indexOf(value);
if (pos>=0) str=str.slice(0,pos)+str.slice(pos+value.length,str.length);
return str;
}

/**
Expand All @@ -145,7 +149,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 +164,7 @@ function unbracketTag(str) {
* 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
*/
function convertToUpperCase(str) {
throw new Error('Not implemented');
return str.toUpperCase();
}

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

/**
Expand All @@ -201,7 +205,25 @@ function extractEmails(str) {
*
*/
function getRectangleString(width, height) {
throw new Error('Not implemented');
let mas="";
for (let i=1;i<=height;i++) {
if (i==1) {
mas+="┌";
for (let i2=2;i2<width;i2++) mas+="─";
mas+="┐\n";
}
if (i>1&&i<height) {
mas+="│";
for (let i2=2;i2<width;i2++) mas+=" ";
mas+="│\n";
}
if (i==height) {
mas+="└";
for (let i2=2;i2<width;i2++) mas+="─";
mas+="┘\n";
}
}
return mas;
}


Expand All @@ -221,7 +243,14 @@ function getRectangleString(width, height) {
*
*/
function encodeToRot13(str) {
throw new Error('Not implemented');
const input='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const output='NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
let pos=-1;
for (let i=0;i<str.length;i++) {
pos=input.indexOf(str[i]);
if (pos>-1) str=str.slice(0,i)+output[pos]+str.slice(i+1,str.length);
}
return str;
}

/**
Expand All @@ -238,7 +267,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 +296,11 @@ function isString(value) {
* 'K♠' => 51
*/
function getCardId(value) {
throw new Error('Not implemented');
const nums=['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
const mass=['♣','♦','♥','♠'];
let num=value.slice(0,-1);
let mas=value.slice(-1);
return mass.indexOf(mas)*13+nums.indexOf(num);
}


Expand Down
Loading