Compare commits
2 Commits
Lesson_1_4
...
master
Author | SHA1 | Date |
---|---|---|
|
f2cb6cf6dd | |
|
25a4e7d988 |
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
// 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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"label": "build_backend",
|
|
||||||
"type": "npm",
|
|
||||||
"script": "build",
|
|
||||||
"path": "/",
|
|
||||||
"problemMatcher": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
188
src/index.ts
188
src/index.ts
|
@ -1,75 +1,137 @@
|
||||||
//Обучение ЦИКЛАМ
|
|
||||||
|
|
||||||
//lesson 1.4 X-MAS TREE
|
// ########################## УЧЕБНЫЙ ТЕКСТ ############################################################
|
||||||
// функиця рисует равномерный треугольник
|
//******************************************************************************************************
|
||||||
function DrawLine(count: number, countP: number){ //рисуем треугольник из звездочек
|
|
||||||
const minimalString = '*';
|
interface People {
|
||||||
const minimalP = ' ';
|
name: string;
|
||||||
|
age: number | undefined;
|
||||||
let result = minimalP.repeat(countP) + minimalString.repeat(count) //с начала рисуем пробелы (countP) а потом зведочки
|
|
||||||
console.log(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function DrawTriangle(height: number, chisloP: number) { //высота - это сколько рядов отрисует
|
let people01: People = {
|
||||||
for(let index = 1; index <= height; ){
|
name: "Kostya",
|
||||||
DrawLine(index * 2 - 1, chisloP - index ); // вызываем функцию DrawLine внутри цикла, chisloN - нужно иметь МАКС значение как в первом уроке
|
age: undefined
|
||||||
index = index +1;
|
};
|
||||||
//console.log(height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log(`===========`); //тут мы считаем пробелы или отступы (для визуального сравенения рисунка)
|
|
||||||
|
|
||||||
//статичный вызов функции
|
let people02: People = {
|
||||||
//DrawTriangle(1); // простой вывод функции на экран
|
name: "Yura",
|
||||||
|
age: 32
|
||||||
let chisloN = 7; //задаем число N ГЛОБАЛЬНАЯ ПЕРЕМЕННАЯ ДЛЯ ОБОИХ ЦИКЛОВ
|
|
||||||
//DrawTriangle(1);
|
|
||||||
//console.log(``); //синтетический перевод корретки
|
|
||||||
//console.log(`============Через цикл одинаковой формы ровно`);
|
|
||||||
// тут мы видим, что цикл вызывается ТРИ раза, хотя функцию вызывали ДВА раза, по этому рисуется три ряда звездочек
|
|
||||||
// т.е. при каждой итерации цикла заново вызов ПЕРВОЙ функции DrawLine
|
|
||||||
for(let index = 1; index <= chisloN;){ // index <= 2 регулируем число елочек
|
|
||||||
DrawTriangle(index, chisloN); //количество вызовов функции DrawLine
|
|
||||||
index = index +1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
//lesson 1.3 ANOTHER TRIANGLE
|
|
||||||
|
|
||||||
|
|
||||||
/*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, нам дает все не четные числа
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//chisloN = chisloN -1 // запись каждый раз уменьшает число пробелов (начиная с макс значения N)
|
let peopleLocation01: PeopleLocation = {
|
||||||
// let index = 1;
|
name: "djdf",
|
||||||
// while(index <= chisloN) {
|
age: 42342,
|
||||||
// DrawLine(index, chisloN - index);
|
location: "dafdf"
|
||||||
// // console.log(`*: ${index}, space: ${chisloN - index}`);
|
}
|
||||||
// index = index + 1;
|
class ProcessingPeoples implements PeopleLocation {
|
||||||
// }
|
name: string;
|
||||||
|
age: number | undefined;
|
||||||
|
location: string = '';
|
||||||
|
|
||||||
//let probel: number = 1;
|
constructor(name: string){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//i++ => i = i + 1
|
let str: string = 'test text';
|
||||||
//i-- => i = i - 1
|
let proc1 = new ProcessingPeoples(str)
|
||||||
//--i => i = i - 1
|
console.log(proc1)
|
||||||
|
proc1.name = 'new test'
|
||||||
|
console.log(proc1)
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let Utka: Duck = new Duck();
|
||||||
|
Utka.log();
|
||||||
|
|
||||||
|
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'
|
||||||
|
console.log(`Object created ${this.type}`)
|
||||||
|
}
|
||||||
|
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
|
||||||
|
];
|
||||||
|
|
||||||
|
let result = array[0]; //мы можем проверить содержание массива с именем array. в квадратных скобках мы указали ноль = это первый эелемент массива.
|
||||||
|
console.log(`результат содержимого массива${JSON.stringify(result)}`); //вывод на экран
|
||||||
|
|
||||||
|
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 => '***'
|
|
||||||
// }*/
|
|
19
src/input.ts
19
src/input.ts
|
@ -1,19 +0,0 @@
|
||||||
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,7 +21,6 @@
|
||||||
"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