Compare commits
2 Commits
master
...
Lesson_1_2
Author | SHA1 | Date |
---|---|---|
|
16cc913cad | |
|
4f1310bbcf |
128
src/index.ts
128
src/index.ts
|
@ -1,120 +1,20 @@
|
||||||
interface People {
|
function DrawLine(count: number){
|
||||||
name: string;
|
const minimalString = '*';
|
||||||
age: number | undefined;
|
console.log(minimalString.repeat(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
let people01: People = {
|
let chisloN: number = 10;
|
||||||
name: "Kostya",
|
|
||||||
age: undefined
|
|
||||||
};
|
|
||||||
|
|
||||||
let people02: People = {
|
//i++ => i = i + 1
|
||||||
name: "Yura",
|
//i-- => i = i - 1
|
||||||
age: 32
|
//--i => i = i - 1
|
||||||
|
|
||||||
|
// for(let i = 0; i < count; i++){
|
||||||
|
// str = str + '*' // i = 0 => str = '*' // i == 1 => '**' // i = 2 => '***'
|
||||||
|
// }
|
||||||
|
|
||||||
|
for(let index = 1; index <= chisloN; index++){
|
||||||
|
DrawLine(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
people01.age = 60;
|
|
||||||
// console.log(people01);
|
|
||||||
// console.log(JSON.stringify(people01));
|
|
||||||
// console.log(people01.age);
|
|
||||||
console.log(`${people01.name} имеет возраст ${people01?.age ?? '40'}`); //Kostya --- 60
|
|
||||||
console.log(`${people02.name} имеет возраст ${people02?.age ?? '40'}`); //Yura --- 32
|
|
||||||
console.log(`${people01.name} имеет возраст ${people02?.age ?? '40'}`);
|
|
||||||
|
|
||||||
interface PeopleLocation extends People {
|
|
||||||
location: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let peopleLocation01: PeopleLocation = {
|
|
||||||
name: "djdf",
|
|
||||||
age: 42342,
|
|
||||||
location: "dafdf"
|
|
||||||
}
|
|
||||||
class ProcessingPeoples implements PeopleLocation {
|
|
||||||
name: string;
|
|
||||||
age: number | undefined;
|
|
||||||
location: string = '';
|
|
||||||
|
|
||||||
constructor(name: string){
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProcessingPeoplesExt extends ProcessingPeoples {
|
|
||||||
isActive: boolean = false;
|
|
||||||
|
|
||||||
constructor(name: string, isActive: boolean){
|
|
||||||
super(name);
|
|
||||||
if(isActive) {
|
|
||||||
this.location = 'Gorkyi street';
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
this.location = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let a: ProcessingPeoples = new ProcessingPeoplesExt("Vasya", true);
|
|
||||||
|
|
||||||
class Duck {
|
|
||||||
type: string = 'Duck';
|
|
||||||
weight: number = 0;
|
|
||||||
log(){
|
|
||||||
console.log("I'm simple duck");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Eateable {
|
|
||||||
eat(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GreyDuck extends Duck implements Eateable{
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.type = 'GreyDuck'
|
|
||||||
}
|
|
||||||
override log(){
|
|
||||||
console.log("I'm grey duck");
|
|
||||||
}
|
|
||||||
|
|
||||||
eat(){
|
|
||||||
console.log("I'm eat");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RedDuck extends Duck implements Eateable {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.type = 'RedDuck'
|
|
||||||
}
|
|
||||||
eat(): void {
|
|
||||||
console.log("I'm eat");
|
|
||||||
}
|
|
||||||
override log(){
|
|
||||||
console.log("I'm red duck");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let duck1 = new RedDuck();
|
|
||||||
let duck2 = new GreyDuck();
|
|
||||||
|
|
||||||
let array: Eateable[] = [
|
|
||||||
duck1,
|
|
||||||
duck2
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let item of array) {
|
|
||||||
item.eat();
|
|
||||||
}
|
|
||||||
|
|
||||||
let array2: Duck[] = [
|
|
||||||
duck2,
|
|
||||||
duck1
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let item of array2) {
|
|
||||||
item.log();
|
|
||||||
}
|
|
||||||
|
|
||||||
array2.filter(item => "eat" in item);
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
import readline from 'node:readline';
|
||||||
|
|
||||||
|
export function ConsoleInput(text: string): string {
|
||||||
|
|
||||||
|
let result: string = '';
|
||||||
|
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
});
|
||||||
|
|
||||||
|
rl.question('Enter something:', value => {
|
||||||
|
result = value;
|
||||||
|
rl.close;
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue