From 5432a0e7a96a8d5f6733a9c61231f1796933204a Mon Sep 17 00:00:00 2001 From: noachase Date: Fri, 7 Sep 2018 00:46:38 +0200 Subject: [PATCH 1/8] Updeted .gitignore/eslint/app.js --- .gitignore | 2 + .vscode/launch.json | 9 +++- 1/.eslintrc.js | 2 +- 2/.eslintrc.js | 2 +- 2/app.js | 117 ++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 119 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 76ba1b6..5acf3ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /**/node_modules .idea +/1 +/2 diff --git a/.vscode/launch.json b/.vscode/launch.json index 84692fd..e0dd40b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "type": "node", "request": "launch", @@ -14,7 +15,13 @@ "type": "node", "request": "launch", "name": "Launch 2 Unit app", - "program": "${workspaceFolder}/2/top10.js" + "program": "${workspaceFolder}/2/app.js" + }, + { + "type": "node", + "request": "launch", + "name": "L. Obj 2 Unit app", + "program": "${workspaceFolder}/2/obj.js" } ] } diff --git a/1/.eslintrc.js b/1/.eslintrc.js index 88167f2..a48d372 100644 --- a/1/.eslintrc.js +++ b/1/.eslintrc.js @@ -14,7 +14,7 @@ module.exports = { ], "linebreak-style": [ "error", - "unix" + "windows" ], "quotes": [ "error", diff --git a/2/.eslintrc.js b/2/.eslintrc.js index 156976f..71fd531 100644 --- a/2/.eslintrc.js +++ b/2/.eslintrc.js @@ -11,7 +11,7 @@ module.exports = { ], "linebreak-style": [ "error", - "unix" + "windows" ], "quotes": [ "error", diff --git a/2/app.js b/2/app.js index d88d688..1cc08b6 100644 --- a/2/app.js +++ b/2/app.js @@ -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'); \ No newline at end of file From d7ded44cb3b967558bf25e3c60f42d12799b5aa6 Mon Sep 17 00:00:00 2001 From: noachase Date: Tue, 11 Sep 2018 21:14:53 +0200 Subject: [PATCH 2/8] eslint linebreakstyle: windows --- 4/.eslintrc.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 4/.eslintrc.js diff --git a/4/.eslintrc.js b/4/.eslintrc.js new file mode 100644 index 0000000..71fd531 --- /dev/null +++ b/4/.eslintrc.js @@ -0,0 +1,28 @@ +module.exports = { + "env": { + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "windows" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ], + "no-console": [ + "off" + ] + } +}; From 7e54263c69191e3aeb47b2089522956ab1f4be92 Mon Sep 17 00:00:00 2001 From: noachase Date: Wed, 12 Sep 2018 01:12:29 +0200 Subject: [PATCH 3/8] added short exp of _random func --- pilot/app.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pilot/app.js b/pilot/app.js index 3d02398..a411e4b 100644 --- a/pilot/app.js +++ b/pilot/app.js @@ -1,4 +1,4 @@ - +"use strict" // declaration class Profiler { constructor(deсimalPlaces = 3){ @@ -26,15 +26,25 @@ class Generator{ generateData(size){ const hugeData = []; for(let i=0; i { const a = Math.random() * this.max + this.min; - const b = Math.round(a * this.accuracy) / this.accuracy + const b = Math.round(a * this.accuracy); return b; + }); } + return hugeData; + + // _random = () => { + // const a = Math.random() * this.max + this.min; + // const b = Math.round(a * this.accuracy); + // return b; + // } + + // function _random() { + // const a = Math.random() * this.max + this.min; + // const b = Math.round(a * this.accuracy) / this.accuracy + // return b; + // } } } From 3d71989eba2e611b21acdbd6de567e8f489850a9 Mon Sep 17 00:00:00 2001 From: noachase Date: Wed, 12 Sep 2018 18:48:48 +0200 Subject: [PATCH 4/8] _random function handled --- pilot/app.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pilot/app.js b/pilot/app.js index a411e4b..5578d81 100644 --- a/pilot/app.js +++ b/pilot/app.js @@ -1,4 +1,4 @@ -"use strict" + // declaration class Profiler { constructor(deсimalPlaces = 3){ @@ -24,27 +24,26 @@ class Generator{ this.accuracy = decimalPlaces * 10; } generateData(size){ - const hugeData = []; + const hugeData = []; for(let i=0; i { - const a = Math.random() * this.max + this.min; - const b = Math.round(a * this.accuracy); - return b; - }); + hugeData.push(_random()); } + return hugeData; - - // _random = () => { + + // var _random = () => { // const a = Math.random() * this.max + this.min; // const b = Math.round(a * this.accuracy); // return b; // } + - // function _random() { - // const a = Math.random() * this.max + this.min; - // const b = Math.round(a * this.accuracy) / this.accuracy - // return b; - // } + + function _random() { + const a = Math.random() * this.max + this.min; + const b = Math.round(a * this.accuracy) / this.accuracy + return b; + } } } From 102b4f62e63ddf9b89f42a3c7f1f21ddfe225fd3 Mon Sep 17 00:00:00 2001 From: noachase Date: Wed, 12 Sep 2018 18:49:29 +0200 Subject: [PATCH 5/8] launch.json --- .vscode/launch.json | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4182b2d..19fa113 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,15 +25,11 @@ { "type": "node", "request": "launch", -<<<<<<< HEAD "name": "L. Obj 2 Unit app", "program": "${workspaceFolder}/2/obj.js" -======= "name": "Launch 3 Unit app", -<<<<<<< HEAD + "program": "${workspaceFolder}/3/app.js" ->>>>>>> 2e62dd628cb1cee6872f526ad96d3e434abb1415 -======= "program": "${workspaceFolder}/3/app2_hw.js" }, { @@ -41,9 +37,7 @@ "request": "launch", "name": "Launch Pilot", "program": "${workspaceFolder}/pilot/app.js" -<<<<<<< HEAD ->>>>>>> 37a5205de350d87c608c574a26d8f4813ed30855 -======= + }, { "type": "node", @@ -56,7 +50,7 @@ "request": "launch", "name": "Closure app ( Anton)", "program": "${workspaceFolder}/4/closure.js" ->>>>>>> b2e4fe7196a9b58dee66f89fffd5fbb517995952 + } ] } From 055e334ecd9676efda2339bfc487223ee4ad829e Mon Sep 17 00:00:00 2001 From: noachase Date: Wed, 12 Sep 2018 23:27:41 +0200 Subject: [PATCH 6/8] Promise test example --- 4/Promises_examples.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 4/Promises_examples.js diff --git a/4/Promises_examples.js b/4/Promises_examples.js new file mode 100644 index 0000000..6986cc6 --- /dev/null +++ b/4/Promises_examples.js @@ -0,0 +1,32 @@ +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 celebrate(){ + console.log('------------------------'); + console.log('EAT=>SLEEP=>RAVE=>REPEAT'); +} + +function getReady(){ + console.log('------------------------'); + console.log('Get pants and shirt steamed etc.'); +} + +applyForJob({}) + .then(approved => console.info('Ur apply has been approved'), + reason => console.error(reason)) + .then(celebrate) + .then(getReady) + .catch(error => console.error(error)); + // function(approved){ + // console.info('Ur apply is approved!'); + // }, + // function(reason){ + // console.error(reason); + // }); \ No newline at end of file From 715b91ef6a72c309543a4fdd917cc6618df78568 Mon Sep 17 00:00:00 2001 From: noachase Date: Wed, 12 Sep 2018 23:32:19 +0200 Subject: [PATCH 7/8] Added launch for Promises_examples.js --- .vscode/launch.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1e3025f..7ccef61 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -58,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" } ] } From ee421d7b2b85d52b71bf74a591fdb84cc91e001e Mon Sep 17 00:00:00 2001 From: noachase Date: Thu, 13 Sep 2018 00:09:54 +0200 Subject: [PATCH 8/8] promises_example_done --- 4/Promises_examples.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/4/Promises_examples.js b/4/Promises_examples.js index 6986cc6..aafef82 100644 --- a/4/Promises_examples.js +++ b/4/Promises_examples.js @@ -8,25 +8,41 @@ function applyForJob(docs) { return promise; } -function celebrate(){ + +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(approved => console.info('Ur apply has been approved'), - reason => console.error(reason)) + .then(approveApply) .then(celebrate) .then(getReady) .catch(error => console.error(error)); - // function(approved){ - // console.info('Ur apply is approved!'); - // }, - // function(reason){ - // console.error(reason); - // }); \ No newline at end of file + + +// function(approved){ +// console.info('Ur apply is approved!'); +// }, +// function(reason){ +// console.error(reason); +// }); \ No newline at end of file