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
26 changes: 26 additions & 0 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,29 @@ class Calculator {
return (this.a + this.b).toString();
}
}

class Decor extends Calculator
{
protected calculators: Calculator;
constructor(a: number, b: number)
{
super(a, b)
this.calculators = new Calculator(a, b)
}
}

class DecorateRu extends Decor
{
public exec(): string
{
return 'Результат сложения ${this.a} + ${this.b} = ${this.calculators.exec()}'
}
}

class DecorateEn extends Decor
{
public exec(): string
{
return 'Result of the addition operation ${this.a} + ${this.b} = ${this.calculators.exec()}'
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не паттерн декоратор

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 балл

28 changes: 23 additions & 5 deletions src/task_2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@
* Когда присваивается некорректный e-mail возбуждается ошибка.
*/

class Example {
public email: string = "";
function check_mail(target: Object, propertyKey: string): any{
let email = "";
let discriptor: PropertyDescriptor = {
get: function()
{
return email;
},
set: function(newmail: string)
{
let mail_write = /[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+/
if (mail_write.test(newmail))
{
email = newmail;
console.log('email valid')

}
else
{
throw "Invalid email"
}
}
}
return discriptor;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 балла

let exampleInstance = new Example();
exampleInstance.email = "fkkldfjg"; // генерирует эксепшен
exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid
4 changes: 2 additions & 2 deletions src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}

const x = undefined;
const x = {m: 7};

console.log(getProperty(x, "m"));
console.log(getProperty(x, "m"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала