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
16 changes: 16 additions & 0 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
* результат в виде строки на английском языке:
* result of the addition operation ${a} + ${b} = ${рассчитанное значение}
*/
function DecorateRu(target:any,method:string,descriptor:PropertyDescriptor) {
descriptor.value = function() {
return `результат сложения ${this.a} + ${this.b} = ${this.a + this.b}`;
}
}

function DecorateEn(target:any,method:string,descriptor:PropertyDescriptor) {
descriptor.value = function() {
return `result of the addition operation ${this.a} + ${this.b} = ${this.a + this.b}`;
}
}


class Calculator {
protected a: number = 0;
Expand All @@ -22,7 +34,11 @@ class Calculator {
}
}

@DecorateEn
public exec(): string {
return (this.a + this.b).toString();
}
}

let calc = new Calculator(100,25);
console.log(calc.exec());

Choose a reason for hiding this comment

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

Тут нужно было реализовать патерн декоратор https://refactoring.guru/ru/design-patterns/decorator/typescript/example

17 changes: 17 additions & 0 deletions src/task_2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
* Когда присваивается корректный e-mail в консоль выводится сообщение email valid.
* Когда присваивается некорректный e-mail возбуждается ошибка.
*/
function valid(target: Object, propertyKey: string):any{
let email = "";
let descriptor:PropertyDescriptor = {
get() {
return email;
},
set(setEmail : string) {
if (setEmail.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){
console.log("email valid");
email = setEmail;
}
else throw "Invalid"
}
}
return descriptor;
}

class Example {
@valid
public email: string = "";
}

Choose a reason for hiding this comment

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

верно, 3 бала


Expand Down
4 changes: 3 additions & 1 deletion src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}

const x = undefined;
const x = {
m:"prop"
};

Choose a reason for hiding this comment

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

3 бала

console.log(getProperty(x, "m"));