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

class BaseDecorator extends Calculator {
protected wrappee: Calculator;

constructor(a: number, b: number) {
super(a, b);
this.wrappee = new Calculator(a, b);
}
}

class DecorateRu extends BaseDecorator{
public exec(): string {
return `результат сложения ${this.a} + ${this.b} = ${this.wrappee.exec()}`;
}
}

class DecorateEn extends BaseDecorator{
public exec(): string {
return `result of the addition operation ${this.a} + ${this.b} = ${this.wrappee.exec()}`;
}

Choose a reason for hiding this comment

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

правильно !
3 бала. молодец.

}
18 changes: 18 additions & 0 deletions src/task_2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ class Example {
let exampleInstance = new Example();
exampleInstance.email = "fkkldfjg"; // генерирует эксепшен
exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid

function validateMail(target: Object, propertyKey: string | symbol): any {
let email = ""
let descriptor: PropertyDescriptor = {
get() {
return email
},
set(newEmail: string) {
if (newEmail !== "" && !/[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+/.test(newEmail)) {
throw 'Invalid email.'
}
console.log('email valid');
email = newEmail;
}
}

Choose a reason for hiding this comment

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

3 бала

return descriptor;
}
2 changes: 1 addition & 1 deletion 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': 14};

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"));