Compare commits
23 Commits
master
...
Lesson_1_4
Author | SHA1 | Date |
---|---|---|
|
499b3c97bc | |
|
6e22791d14 | |
|
56ae848aee | |
|
706feb8bd6 | |
|
1139f8acbd | |
|
30be821446 | |
|
d10df6e533 | |
|
417acb8e4b | |
|
5bef125273 | |
|
3071bb4746 | |
|
94e33222b2 | |
|
7e7301b1ab | |
|
abc5eecbe6 | |
|
b3d2bbb9da | |
|
edfa057838 | |
|
68be4c01bf | |
|
b0eb9c869a | |
|
03c74d8769 | |
|
5509a95a6e | |
|
5293c1ee31 | |
|
7f67cd98ca | |
|
16cc913cad | |
|
4f1310bbcf |
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${workspaceFolder}\\src\\index.ts",
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "build_backend"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build_backend",
|
||||||
|
"type": "npm",
|
||||||
|
"script": "build",
|
||||||
|
"path": "/",
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
167
src/index.ts
167
src/index.ts
|
@ -1,120 +1,75 @@
|
||||||
interface People {
|
//Обучение ЦИКЛАМ
|
||||||
name: string;
|
|
||||||
age: number | undefined;
|
//lesson 1.4 X-MAS TREE
|
||||||
|
// функиця рисует равномерный треугольник
|
||||||
|
function DrawLine(count: number, countP: number){ //рисуем треугольник из звездочек
|
||||||
|
const minimalString = '*';
|
||||||
|
const minimalP = ' ';
|
||||||
|
|
||||||
|
let result = minimalP.repeat(countP) + minimalString.repeat(count) //с начала рисуем пробелы (countP) а потом зведочки
|
||||||
|
console.log(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
let people01: People = {
|
function DrawTriangle(height: number, chisloP: number) { //высота - это сколько рядов отрисует
|
||||||
name: "Kostya",
|
for(let index = 1; index <= height; ){
|
||||||
age: undefined
|
DrawLine(index * 2 - 1, chisloP - index ); // вызываем функцию DrawLine внутри цикла, chisloN - нужно иметь МАКС значение как в первом уроке
|
||||||
};
|
index = index +1;
|
||||||
|
//console.log(height);
|
||||||
let people02: People = {
|
|
||||||
name: "Yura",
|
|
||||||
age: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//console.log(`===========`); //тут мы считаем пробелы или отступы (для визуального сравенения рисунка)
|
||||||
|
|
||||||
class ProcessingPeoplesExt extends ProcessingPeoples {
|
//статичный вызов функции
|
||||||
isActive: boolean = false;
|
//DrawTriangle(1); // простой вывод функции на экран
|
||||||
|
|
||||||
constructor(name: string, isActive: boolean){
|
let chisloN = 7; //задаем число N ГЛОБАЛЬНАЯ ПЕРЕМЕННАЯ ДЛЯ ОБОИХ ЦИКЛОВ
|
||||||
super(name);
|
//DrawTriangle(1);
|
||||||
if(isActive) {
|
//console.log(``); //синтетический перевод корретки
|
||||||
this.location = 'Gorkyi street';
|
//console.log(`============Через цикл одинаковой формы ровно`);
|
||||||
}
|
// тут мы видим, что цикл вызывается ТРИ раза, хотя функцию вызывали ДВА раза, по этому рисуется три ряда звездочек
|
||||||
else{
|
// т.е. при каждой итерации цикла заново вызов ПЕРВОЙ функции DrawLine
|
||||||
this.location = '';
|
for(let index = 1; index <= chisloN;){ // index <= 2 регулируем число елочек
|
||||||
}
|
DrawTriangle(index, chisloN); //количество вызовов функции DrawLine
|
||||||
}
|
index = index +1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let a: ProcessingPeoples = new ProcessingPeoplesExt("Vasya", true);
|
|
||||||
|
|
||||||
class Duck {
|
|
||||||
type: string = 'Duck';
|
|
||||||
weight: number = 0;
|
//lesson 1.3 ANOTHER TRIANGLE
|
||||||
log(){
|
|
||||||
console.log("I'm simple duck");
|
|
||||||
}
|
/*let chisloN: number = 5; //эмуляция вводу а с клавиатуры числа N
|
||||||
|
|
||||||
|
|
||||||
|
for(let index = 1; index < chisloN; ){
|
||||||
|
//тут нарисовал статично, как должен рисоваться треугольник
|
||||||
|
//DrawLine(1 , 3);
|
||||||
|
//DrawLine(3 , 2);
|
||||||
|
//DrawLine(5 , 1);
|
||||||
|
DrawLine(index * 2 - 1, chisloN - index);
|
||||||
|
//DrawLine(1, 2); 1 * 2 - 1
|
||||||
|
//DrawLine(3, 1); 2 * 2 - 1
|
||||||
|
//DrawLine(5, 0); 3 * 2 - 1
|
||||||
|
|
||||||
|
|
||||||
|
index = index +1; //запись, index = index +2, нам дает все не четные числа
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Eateable {
|
//chisloN = chisloN -1 // запись каждый раз уменьшает число пробелов (начиная с макс значения N)
|
||||||
eat(): void;
|
// let index = 1;
|
||||||
}
|
// while(index <= chisloN) {
|
||||||
|
// DrawLine(index, chisloN - index);
|
||||||
|
// // console.log(`*: ${index}, space: ${chisloN - index}`);
|
||||||
|
// index = index + 1;
|
||||||
|
// }
|
||||||
|
|
||||||
class GreyDuck extends Duck implements Eateable{
|
//let probel: number = 1;
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.type = 'GreyDuck'
|
|
||||||
}
|
|
||||||
override log(){
|
|
||||||
console.log("I'm grey duck");
|
|
||||||
}
|
|
||||||
|
|
||||||
eat(){
|
//i++ => i = i + 1
|
||||||
console.log("I'm eat");
|
//i-- => i = i - 1
|
||||||
}
|
//--i => i = i - 1
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
// for(let i = 0; i < count; i++){
|
||||||
|
// str = str + '*' // i = 0 => str = '*' // i == 1 => '**' // i = 2 => '***'
|
||||||
|
// }*/
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||||
/* Completeness */
|
/* Completeness */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
||||||
|
"sourceMap": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue