Skip to content
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
<<<<<<< HEAD
/**/node_modules
.idea
/1
/2
=======
/**/node_modules/
.idea/
>>>>>>> b2e4fe7196a9b58dee66f89fffd5fbb517995952
21 changes: 20 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "HOMEWORK 3 Unit app",
"program": "${workspaceFolder}/3/App2_hw.js"
},
{
"type": "node",
"request": "launch",
Expand All @@ -16,17 +22,24 @@
"name": "Launch 2 Unit app",
"program": "${workspaceFolder}/2/top10.js"
},
{
"type": "node",
"request": "launch",
"name": "L. Obj 2 Unit app",
"program": "${workspaceFolder}/2/obj.js"
},
{
"type": "node",
"request": "launch",
"name": "Launch 3 Unit app",
"program": "${workspaceFolder}/3/app2.js"
"program": "${workspaceFolder}/3/app2_hw.js"
},
{
"type": "node",
"request": "launch",
"name": "Launch Pilot",
"program": "${workspaceFolder}/pilot/app.js"

},
{
"type": "node",
Expand All @@ -45,6 +58,12 @@
"request": "launch",
"name": "CallBack app ( Anton)",
"program": "${workspaceFolder}/4/callback.js"
},
{
"type": "node",
"request": "launch",
"name": "Promises app ( Evgen)",
"program": "${workspaceFolder}/4/Promises_examples.js"
}
]
}
2 changes: 1 addition & 1 deletion 1/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion 2/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down
117 changes: 107 additions & 10 deletions 2/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,116 @@
* "}{}{" invalid,
* "{{}{}{}}" valid;
*/
// var str = '{}}{{}',
// strLength = str.length,
// lastChar = str.charAt(strLength-1),
// firstChar = str.charAt(0);
// console.log('First cond: EVEN number of chars: ' + strLength);
// console.log('Second cond: Must end with "}" : ' + lastChar);
// console.log('Thrid cond: Must start from "{" : ' + firstChar);
// // if (str.indexOf('}') > 0 && firstChar == '{') {

function validation(x){
// последовательно просмотреть все символы один за другим
// 1, 2, 3, 4, ....
//
// если у нас длина строки нечетная, тогда сразу invalid
// введем счетчик и если { тогда мы его увеличиваем, если } тогда уменьшаем
// // }

return true;
// if (strLength % 2 == 0 && lastChar == '}' && firstChar == '{' && (str.indexOf('}') > 0 && firstChar == '{')) {
// console.log('THIS STRING IS VALID');
// } else {
// console.log('NEIN!! STRING IS INVALID');
// }

const str = '{{}}}{{}';
const valSt = 'Valid string';
const invalSt = 'Invalid string';
var bracketCount = 0;

function StrVal(str){

for (let i = 0; i < str.length; i++ ) {
if (str[i] == '{' ) {
bracketCount++;
}
else if (str[i] == '}') {
bracketCount-- ;
if (bracketCount < 0) {
return invalSt;
}
}
}

if (bracketCount == 0) {
return valSt;
}
return invalSt;

}
// if (str === false ){
// console.log('Invalid string Str');
// } else{
// console.log('Valid Str');
// }
console.log(StrVal(str));

// function validation(x){
// // последовательно просмотреть все символы один за другим
// // 1, 2, 3, 4, ....
// //
// // если у нас длина строки нечетная, тогда сразу invalid
// // введем счетчик и если { тогда мы его увеличиваем, если } тогда уменьшаем

// return true;
// }

// const validatedData = '{{}';

// const isValid = validation(validatedData);

// console.log(`"${validatedData}" is Valid ? "${isValid}"`);
//---------------------------Task4----------------------------
//array 0..100
// var timeBefore = Date.now();
// var randomArr = [];

// for (var i = 0 ; i <= 100; i++) {
// randomArr.push(+i);
// }
// var timeAfrer = Date.now();
// var timeDiff = timeBefore - timeAfrer;
// console.log('finding top10 took' + timeDiff + 'ms');

// var timeBefore = Date.now();
const timeBefore = new Date().getTime() / 1000;
function RandomNum(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function CreateRandomArr(len) {
// var len = len || 20;
for (var i = 0, arr = []; i < len; i++) {
arr.push(RandomNum(0, 1000));
}
return arr;
}
var arr = CreateRandomArr(1000000);
const n = arr.length; //getting array.length in n

console.log('Number of elements in the array is: ' + n);

const validatedData = '{{}';
function CompareNum(a, b) {
return a - b;
}
//find the top10 from arr
function FindTop10() {
let sortedArray = arr.sort(CompareNum);
let top10 = [];
for (let i = sortedArray.length - 1; i >= (sortedArray.length-10); i--) {
top10.push(sortedArray[i]);
}
return top10;
}

const isValid = validation(validatedData);
var top10Arr = FindTop10();
console.log('HERE WE GO! TOP 10: ' + top10Arr);

console.log(`"${validatedData}" is Valid ? "${isValid}"`);
var timeAfrer = new Date().getTime() / 1000;
var timeDiff = timeBefore - timeAfrer;
console.log('Time spent on executing the script' + timeDiff + ' sec');
2 changes: 1 addition & 1 deletion 3/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down
57 changes: 57 additions & 0 deletions 3/App2_hw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class ArrayMaker {
constructor(size, min = 0 , max = 1000) {
this.size = size;
this.min = min;
this.max = max;
}
_numRandomizer(){
return Math.round(Math.random()*this.max + this.min);
}
createArray(){
const array = [];
for (let i = 0; i < this.size; i++ ){
array.push(this._numRandomizer);
}
return array;

}

}

class Timer {
constructor(isSec){
this.isSec = isSec;
console.log(`Created as "${this.isSec ? 'sec' : 'ms'}" timer`);
}
start(){
const now = new Date();
this.timer = now.getTime();
console.log(`Started at ${now.getHours()}: ${now.getMinutes()}`);
}
finish() {
const now = new Date();
const timeDiff = now.getTime() - this.timer;
console.log(`finished at ${ this.isSec ? timeDiff / 1000 : timeDiff } sec`);
}


}

const timerSec = new Timer(true);
const timerMs = new Timer(true);
const arrayMaker = new ArrayMaker (1000000);
// console.log(arrayMaker);
const array1 = arrayMaker.createArray();
// console.log(array1);

try {
timerSec.start();
timerMs.start();

timerSec.finish();
timerMs.finish();

console.log(`Array ${array1.length} was created`);
} catch(err){
console.error(err);
}
30 changes: 24 additions & 6 deletions 3/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
This array must be generated from random 0...1000 and print duration (sec)
*/

const min = 5;
const min = 0;
const max = 1000;
const size = 10000000;
const size = 1000000;

class Timer {
constructor(isSeconds){
Expand Down Expand Up @@ -37,19 +37,37 @@ function generateRandomArray(size, min, max){
function randomElement(min, max){
return Math.round(Math.random() * max * 100 + min) / 100;
}



}
// 'use strict'
//HOW DO I DO THIS
function compareAb(a, b){
return a - b;
}
let Filtre = class Compare {
Co
}(a, b) { a - b;}

function getTop10() {
const sortedArr = randomArray.sort(compareAb);
const top10 = [];
for (let i = sortedArr.length - 1; i>= (sortedArr.length-10); i--) {
top10.push(sortedArr[i]);
}
return top10;
}

try {
timerSeconds.start();
timerMilliseconds.start();
const data = generateRandomArray(size, min, max);
const top10Here = getTop10();
timerSeconds.finish();
timerMilliseconds.finish();

console.log(`Array ${data.length} was created`);
} catch(err){
console.error(err);
}



}
2 changes: 1 addition & 1 deletion 4/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down
48 changes: 48 additions & 0 deletions 4/Promises_examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function applyForJob(docs) {
console.log('Applying for a job...');
let promise = new Promise(function(resolve, reject){
setTimeout(function(){
Math.random() > 0.5 ? resolve({}) : reject('Apply for the job has been rejected');
}, 1500);
});
return promise;
}


function approveApply(permission){
console.log('WE GOT APPROVED');
return permission;
}
// approved => {
// console.info('Ur apply has been approved');
// return approved;
// };

function celebrate(permission){
console.log(permission);
console.log('------------------------');
console.log('EAT=>SLEEP=>RAVE=>REPEAT');
return new Promise(function(resolve, reject){
setTimeout(() => resolve(permission), 1500);
});
}

function getReady(){
console.log('------------------------');
console.log('Get pants and shirt steamed etc.');
return console.log('We are ready to work,' + {});
}

applyForJob({})
.then(approveApply)
.then(celebrate)
.then(getReady)
.catch(error => console.error(error));


// function(approved){
// console.info('Ur apply is approved!');
// },
// function(reason){
// console.error(reason);
// });
Loading