Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit 6115d90

Browse files
committed
Add all
1 parent 10c58a7 commit 6115d90

18 files changed

+875
-0
lines changed

Iterators/class.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
class TaskList {
4+
constructor() {
5+
this.tasks = [];
6+
}
7+
8+
addTasks(...task) {
9+
this.tasks = this.tasks.concat(task);
10+
}
11+
[Symbol.iterator]() {
12+
return new ArrayIterator(this.tasks);
13+
}
14+
15+
}
16+
class ArrayIterator {
17+
constructor(array) {
18+
this.array = array.map(array => array).sort();
19+
this.index = 0;
20+
}
21+
next() {
22+
let result = { value: undefined, done: true };
23+
if ( this.index < this.array.length ) {
24+
result.value = this.array[this.index];
25+
result.done = false;
26+
this.index +=1;
27+
}
28+
return result;
29+
}
30+
}
31+
32+
let taskList = new TaskList();
33+
taskList.addTasks("Изучить JavaScript","Изучить ES6");
34+
35+
for (let task of taskList) {
36+
console.log(task);
37+
}

Iterators/randomGenerator.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
let randomGenerator = {
4+
generate() {
5+
return this[Symbol.iterator]();
6+
} ,
7+
8+
[Symbol.iterator]() {
9+
let count = 0;
10+
11+
return {
12+
next() {
13+
let value = Math.ceil(Math.random() * 100);
14+
let done = count > 9; //change this parameter to control randomizing
15+
count++;
16+
return {value, done};
17+
}
18+
};
19+
}
20+
};
21+
let random = randomGenerator.generate(); // generate one random number
22+
console.log(random.next().value);
23+
// console.log(random.next().done);
24+
for(let random of randomGenerator) { // generate ? random numbers
25+
console.log(random)
26+
}

Practika.1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
function sum(a, b) {
4+
if (typeof(a) === 'number' && typeof(b) === 'number') {
5+
return a + b;
6+
} else {
7+
throw new Error('a and b should be numbers');
8+
}
9+
}
10+
11+
try {
12+
console.log(sum(2, 3));
13+
} catch (e) {
14+
console.log(e.message);
15+
}
16+
17+
try {
18+
console.log(sum(7, 'A'));
19+
} catch (e) {
20+
console.log(e.message);
21+
}

Practika.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
let wtvr =0;
2+
const fun = (...args) => {
3+
if(args.length % 2 === 0 && args.length !== 0) {
4+
for(let value of args){
5+
wtvr += value ;
6+
}
7+
return fun;
8+
}
9+
if (args.length % 2 === 1 && args.length !== 0) {
10+
for(let value of args){
11+
wtvr -= value ;
12+
}
13+
return fun;
14+
}
15+
if(args.length === 0)
16+
return wtvr ;
17+
}
18+
console.log(fun(4,5,9)(141,18)());
19+
// (new Date().toLocaleString('ru', {
20+
// weekday: 'long',
21+
// year: 'numeric',
22+
// month: 'long',
23+
// day: 'numeric',
24+
// hour: 'numeric',
25+
// minute: 'numeric',
26+
// second: '2-digit',
27+
// }));
28+
29+
// const args = [1,2,3];
30+
// const a = () => {for(let value of args){
31+
// wtvr -= value ;
32+
// }
33+
// return wtvr;
34+
// }
35+
// console.log(a);

basfa.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
const puppeteer = require('puppeteer');
4+
// const devices = require('puppeteer/DeviceDescriptors');
5+
6+
(async () => {
7+
const browser = await puppeteer.launch({headless: false});
8+
const page = await browser.newPage();
9+
// await page.emulate(devices['iPhone 6']);
10+
await page.goto('https://docs.google.com/spreadsheets/d/1qxsET43yE_B6UYMZC2Cb4aheUcXeKdBAUmAkeoQn-eA/edit#gid=1811612640');
11+
await page.setViewport({width: 2000, height: 2000})
12+
await page.waitFor(1000);
13+
await page.screenshot({path: 'kel1.png'});
14+
// await page.screenshot({path: 'full1.png', fullPage: true});
15+
await browser.close();
16+
})();

class.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
class Task {
3+
constructor(title = Task.getDefault_Title()) {
4+
this._title = title;
5+
this._done = false;
6+
}
7+
8+
get done() {
9+
return this._done ? 'Complited' : 'It`ll be complited as soon as it can be'
10+
}
11+
12+
set done(value) {
13+
if(typeof value === 'boolean')
14+
this._done = value;
15+
else
16+
console.error('Дэбилы, тут нужен булеан')
17+
}
18+
19+
complite() {
20+
this.done = true;
21+
}
22+
23+
static getDefault_Title() {
24+
return 'My upcomming task';
25+
}
26+
}
27+
let task = new Task('Learn class in ES6');
28+
console.log(task._done,task.done);
29+
task.complite();
30+
console.log(task._done,task.done);
31+
32+
33+
// let task2 = new Task();
34+
// console.log(task._title);
35+
// console.log(task2._title);
36+
// task.complite();

getRozklad.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const puppeteer = require('puppeteer');
3+
4+
// let scrape =
5+
(async () => {
6+
const browser = await puppeteer.launch({headless: false});
7+
const page = await browser.newPage();
8+
9+
10+
await page.goto('http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx');
11+
await page.waitFor(1000);
12+
await page.focus('#ctl00_MainContent_ctl00_txtboxGroup');
13+
await page.type('#ctl00_MainContent_ctl00_txtboxGroup','ІП-71',{delay: 100}); //Type the group
14+
// await page.keyboard.press('ArrowDown',{delay: 100});
15+
await page.waitForSelector('#ctl00_MainContent_ctl00_btnShowSchedule');
16+
await page.click('#ctl00_MainContent_ctl00_btnShowSchedule',{clickCount: 100000000000});
17+
await page.keyboard.press('Enter',{delay: 100});
18+
await page.waitFor(8000);
19+
20+
// const result = await page.evaluate(() => {
21+
// let data = [];
22+
// let elems = document.querySelectorAll('.product_pod');
23+
// for(let elem of elems){
24+
// let title = elem.childNodes[5].innerText;
25+
// let price = elem.childNodes[7].children[1].innerText;
26+
27+
// data.push({title, price});
28+
29+
// }
30+
// return data;
31+
// });
32+
await browser.close();
33+
// return result;
34+
})();
35+
36+
// scrape().then((value) => {
37+
// console.log(value);
38+
// });

get_set.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
function User(fullName) {
3+
this.fullName = fullName;
4+
let separate = this.fullName.split(' ');
5+
Object.defineProperties(this,{
6+
firstName : {
7+
get: () => this.firstName = separate[0],
8+
set: value => {
9+
separate[0] = value;
10+
return this.fullName = separate.join(' ');
11+
}
12+
13+
},
14+
lastName: {
15+
get: () => this.lastName = separate[1] ,
16+
set: value => {
17+
separate[1] = value;
18+
return this.fullName = separate.join(' ');
19+
}
20+
21+
}
22+
});
23+
}
24+
25+
26+
let vasya = new User("Петя Петров");
27+
console.log( vasya.firstName );
28+
console.log( vasya.lastName );
29+
vasya.lastName = 'Сидоров';
30+
console.log( vasya.fullName );
31+
let anon = new User("TheMan WHoSoldTheWorld");
32+
console.log( anon.fullName);
33+
anon.firstName = 'TheWoman';
34+
console.log( anon.fullName);
35+

index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<button></button>
11+
<button></button>
12+
<button></button>
13+
<button></button>
14+
<button></button>
15+
<script src="randomGenerator.js"></script>
16+
</body>
17+
</html>

inheritance.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';
2+
3+
class Task {
4+
constructor(title) {
5+
this._title = title;
6+
this._done = false;
7+
Task.count += 1;
8+
console.log(`The task is initialized : "${this._title}"`);
9+
}
10+
11+
complite() {
12+
this.done = false ;
13+
console.log(`${this._title} complited.`);
14+
}
15+
16+
get done() {
17+
return this._done ? `The ${this._title} is complited` : 'Wasted'
18+
}
19+
20+
set done(v) {
21+
if (typeof this._done === 'boolean') this._done = v;
22+
else console.log('type true or false')
23+
}
24+
25+
get title() {
26+
return this._title
27+
}
28+
29+
set title(v) {
30+
if(typeof v === 'String')this._title = v
31+
}
32+
33+
static getDefaultTitle() {
34+
return 'The task'
35+
}
36+
}
37+
Task.count = 0;
38+
39+
class SubTask extends Task {
40+
constructor(title,parent) {
41+
super(title);
42+
this.parent = parent;
43+
}
44+
45+
complite() {
46+
super.complite();
47+
console.log(`Subtask '${this._title}' is complited`);
48+
}
49+
}
50+
// Usage
51+
52+
const task = new Task('Learn inheritance in JS');
53+
const subtask = new SubTask('Learn inheritance in ES6',Task);
54+
55+
// console.log(task.title);
56+
// console.log(subtask.title);
57+
58+
// subtask.title = 'New title';
59+
// console.log(subtask.title);
60+
61+
console.log(`Tasks count = ${SubTask.count}`);
62+
console.log(`The DefaultTitle is '${SubTask.getDefaultTitle()}'`);
63+
64+
subtask.complite();
65+
console.log(`Status : ${subtask.done}`);

0 commit comments

Comments
 (0)