From 77f0198998d7a27be3d5310992a16c640e6190b6 Mon Sep 17 00:00:00 2001 From: Yurii Drahomaretskyi Date: Tue, 28 Jul 2020 22:05:00 +0200 Subject: [PATCH 1/3] zadanie01 - done --- .idea/.gitignore | 5 +++++ .idea/Node.js_challenge_dzien_2.iml | 12 ++++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ app/data/zadanie01/sum.txt | 1 + app/zadanie01.js | 22 +++++++++++++++++++++- 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Node.js_challenge_dzien_2.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Node.js_challenge_dzien_2.iml b/.idea/Node.js_challenge_dzien_2.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/Node.js_challenge_dzien_2.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..48b5c65 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/data/zadanie01/sum.txt b/app/data/zadanie01/sum.txt index e69de29..615088b 100644 --- a/app/data/zadanie01/sum.txt +++ b/app/data/zadanie01/sum.txt @@ -0,0 +1 @@ +108 \ No newline at end of file diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..63093a2 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,21 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); + +fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => { + if (err === null){ + const arr = JSON.parse(data); + const result = arr.reduce((acc, num) => { + return acc + num + }); + console.log(result); + fs.writeFile('./data/zadanie01/sum.txt', '108', err => { + if (err === null) { + console.log('zapisano') + } else { + console.log('Błąd podczas zapisu pliku!', err); + } + }) + } else { + console.log('Błąd podczas odczytu pliku!', err); + } +}); \ No newline at end of file From f8c79a30f6c8c0f06834fa99a3f01935d4ef7304 Mon Sep 17 00:00:00 2001 From: Yurii Drahomaretskyi Date: Wed, 29 Jul 2020 12:14:22 +0200 Subject: [PATCH 2/3] zadanie02 - done --- app/zadanie02.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..0cad4b1 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,45 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +const path = require('path'); +const folderPath = './data/zadanie02'; + +// fs.readdir('./data/zadanie02', (err, files) => { +// if (err === null) { +// console.log('Lista plików:'); +// files.forEach(file => { +// console.log(file); +// // try { +// // const data = fs.readFileSync(file) +// // console.log(data) +// // } catch (err) { +// // console.error(err) +// // } +// fs.readFile(file, 'utf8', (err, data) => { +// if (err === null) { +// console.log(data); +// } else { +// console.log('Błąd podczas odczytu pliku!', err); +// } +// }); +// }); +// +// } else { +// console.log('Błąd podczas listowania katalogu!', err); +// } +// +// }); + +const filesLinks = fs.readdirSync(folderPath).map(fileName => { + return path.join(folderPath, fileName) +}); + +filesLinks.forEach(file => { + fs.readFile(file, 'utf8', (err, data) => { + if (err === null) { + console.log(data); + } else { + console.log('Błąd podczas odczytu pliku!', err); + } + }) +}) + From 43862f92ba85de997cd30c52e7412004fb1d0cf4 Mon Sep 17 00:00:00 2001 From: Yurii Drahomaretskyi Date: Wed, 29 Jul 2020 13:23:41 +0200 Subject: [PATCH 3/3] zadanieDnia - done --- app/data/zadanieDnia/test.txt | 10 +++++----- app/zadanieDnia.js | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 47c17e3..0bcff2e 100644 --- a/app/data/zadanieDnia/test.txt +++ b/app/data/zadanieDnia/test.txt @@ -1,7 +1,7 @@ -You Don't Know JS: ES6 & Beyond -Foreword +yOu dOn't kNoW Js: Es6 & BeYoNd +fOrEwOrD -Kyle Simpson is a thorough pragmatist. +kYlE SiMpSoN Is a tHoRoUgH PrAgMaTiSt. -I can't think of higher praise than this. To me, these are two of the most important qualities that a software developer must have. That's right: must, not should. Kyle's keen ability to tease apart layers of the JavaScript programming language and present them in understandable and meaningful portions is second to none. -[https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20%26%20beyond/foreword.md] \ No newline at end of file +i cAn't tHiNk oF HiGhEr pRaIsE ThAn tHiS. tO Me, ThEsE ArE TwO Of tHe mOsT ImPoRtAnT QuAlItIeS ThAt a sOfTwArE DeVeLoPeR MuSt hAvE. tHaT'S RiGhT: mUsT, nOt sHoUlD. kYlE'S KeEn aBiLiTy tO TeAsE ApArT LaYeRs oF ThE JaVaScRiPt pRoGrAmMiNg lAnGuAgE AnD PrEsEnT ThEm iN UnDeRsTaNdAbLe aNd mEaNiNgFuL PoRtIoNs iS SeCoNd tO NoNe. +[hTtPs://gItHuB.CoM/GeTiFy/yOu-dOnT-KnOw-jS/BlOb/mAsTeR/Es6%20%26%20BeYoNd/fOrEwOrD.Md] \ No newline at end of file diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..6c8ce96 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,21 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); + +const alternativeCase = string => string.split('') + .map((c,i) => i & 1 ? c.toUpperCase() : c.toLowerCase()).join(''); + +fs.readFile('./data/zadanieDnia/test.txt', 'utf8', (err, data) => { + if (err === null){ + // console.log(data); + const edited = alternativeCase(data); + fs.writeFile('./data/zadanieDnia/test.txt', edited, err => { + if (err === null) { + console.log('zapisano', edited); + } else { + console.log('Błąd', err); + } + }) + } else { + console.log(err); + } +});