Compare commits
38 Commits
master
...
Lesson_1_5
Author | SHA1 | Date |
---|---|---|
|
e166b28043 | |
|
458f6de3fb | |
|
76779576ff | |
|
6f44e6a0f8 | |
|
dba600406a | |
|
ef7410dd10 | |
|
6428289c60 | |
|
cd986463d6 | |
|
31957f0af5 | |
|
7823885587 | |
|
ca5807d864 | |
|
8cd0772025 | |
|
507e1f5106 | |
|
0773b73f34 | |
|
450c6d746b | |
|
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,71 @@
|
||||||
interface People {
|
//*****************************************************************
|
||||||
name: string;
|
//#################### Обучение ЦИКЛАМ ##########################
|
||||||
age: number | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
let people01: People = {
|
|
||||||
name: "Kostya",
|
|
||||||
age: undefined
|
|
||||||
};
|
|
||||||
|
|
||||||
let people02: People = {
|
//lesson 1.5.1 SUM OF NUMBERS
|
||||||
name: "Yura",
|
|
||||||
age: 32
|
|
||||||
}
|
|
||||||
|
|
||||||
people01.age = 60;
|
//## ЗАДАЧА ##
|
||||||
// console.log(people01);
|
//Если выписать все натуральные числа меньше 10, кратные 3, или 5, то получим 3, 5, 6 и 9.
|
||||||
// console.log(JSON.stringify(people01));
|
//Сумма этих чисел будет равна 23.
|
||||||
// console.log(people01.age);
|
//Напишите программу, которая выводит на экран сумму всех чисел меньше 1000, кратных 3, или 5.
|
||||||
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 {
|
//#1 натуральное число от 1 до 10 (числа которые
|
||||||
location: string;
|
//#2 Натуральные числа (от лат. naturalis — «естественный») — числа, возникающие естественным образом при счёте. Примеры: 1, 2, 3, 4, 5, 6, 7 и)
|
||||||
}
|
//#3 Числа, кратные 3, или 5 — это числа, которые делятся на 3 или на 5 без остатка.
|
||||||
|
|
||||||
let peopleLocation01: PeopleLocation = {
|
|
||||||
name: "djdf",
|
|
||||||
age: 42342,
|
|
||||||
location: "dafdf"
|
|
||||||
}
|
|
||||||
class ProcessingPeoples implements PeopleLocation {
|
|
||||||
name: string;
|
|
||||||
age: number | undefined;
|
|
||||||
location: string = '';
|
|
||||||
|
|
||||||
constructor(name: string){
|
// && - AND
|
||||||
this.name = name;
|
// || - OR
|
||||||
}
|
// !
|
||||||
}
|
/*
|
||||||
|
function analise (chislo: number){
|
||||||
class ProcessingPeoplesExt extends ProcessingPeoples {
|
return chislo % 3 ==0 || chislo % 5 ==0;
|
||||||
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(){
|
let p = analise(3);
|
||||||
console.log("I'm eat");
|
|
||||||
|
let a = 0;
|
||||||
|
for(let index = 1; index < 1000; ){
|
||||||
|
|
||||||
|
if (analise(index)){
|
||||||
|
//console.log(index);
|
||||||
|
a = a + index;
|
||||||
}
|
}
|
||||||
}
|
index = index + 1;
|
||||||
|
//break //оператор прерывания цикла (сразуже заканчивает цикл)
|
||||||
class RedDuck extends Duck implements Eateable {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.type = 'RedDuck'
|
|
||||||
}
|
}
|
||||||
eat(): void {
|
console.log(`сумма: ${a}`);
|
||||||
console.log("I'm eat");
|
*/
|
||||||
|
|
||||||
|
//найти формулу (в инете) арифметич. прогрессии и как эту формулу реализовать в коде
|
||||||
|
// найти как узнать А-n число. "Это число А-n" можно получить циклом в обратной последовательности от 1000 и идти к меньшему и найти первый попавшийся элемент.
|
||||||
|
|
||||||
|
/*
|
||||||
|
Формула n-го члена арифметической прогрессии: an = a1 + d(n − 1), где:
|
||||||
|
a1 — первый член прогрессии;
|
||||||
|
|
||||||
|
d — разность между любыми двумя соседними членами;
|
||||||
|
|
||||||
|
n — порядковый номер члена прогрессии.
|
||||||
|
|
||||||
|
С помощью этой формулы можно найти любой член арифметической прогрессии, если известны её первый член и разность.
|
||||||
|
|
||||||
|
Формула для нахождения суммы первых n членов арифметической прогрессии: Sn = (a1 + an)⋅n/2, где n — число членов последовательности.
|
||||||
|
*/
|
||||||
|
function analise (chislo: number){
|
||||||
|
return chislo % 3 ==0 || chislo % 5 ==0;
|
||||||
}
|
}
|
||||||
override log(){
|
|
||||||
console.log("I'm red duck");
|
let p = analise(3);
|
||||||
|
|
||||||
|
let a = 0;
|
||||||
|
for(let index = 1000; index = 1; ){ // обратный цикл от 1000 до 1, для поиска первого элемента!
|
||||||
|
|
||||||
|
if (analise(index)){
|
||||||
|
//console.log(index);
|
||||||
|
a = a + index;
|
||||||
}
|
}
|
||||||
}
|
index = index + 1;
|
||||||
|
//break //оператор прерывания цикла (сразуже заканчивает цикл)
|
||||||
let duck1 = new RedDuck();
|
}
|
||||||
let duck2 = new GreyDuck();
|
console.log(`сумма: ${a}`);
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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