From 0d14f518c8cfcb3a3af4f6b20ce8584aca0c49fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 12:24:03 +0100 Subject: [PATCH 1/6] Ex. 01 done --- .idea/vcs.xml | 6 ++++++ app/data/sum.txt | 1 + app/data/zadanie01/sum.txt | 1 + app/zadanie01.js | 26 +++++++++++++++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 app/data/sum.txt 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/sum.txt b/app/data/sum.txt new file mode 100644 index 0000000..91498a5 --- /dev/null +++ b/app/data/sum.txt @@ -0,0 +1 @@ +1,2,7,20,56,22 \ 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..57c2725 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,25 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +fs.readFile('../app/data/zadanie01/input.json', 'utf8', (err, data) => { + if (err === null){ + console.log('Poprawnie odczytano plik.', data); + let arr = JSON.parse(data); + function sum (x){ + let y= 0; + for (i=0; i { + if (err === null){ + console.log('Zapisano sumę poprawnie!'); + } else { + console.log('Błąd podczas zapisu sumy w pliku!', err); + } + }); + + } else { + console.log('Błąd podczas odczytu pliku jSON!', err); + } +}); \ No newline at end of file From 47b099bd1e0aec8a16e49368de3ef31cff969322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 12:34:44 +0100 Subject: [PATCH 2/6] Ex. 02 done --- app/zadanie02.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..1c226d9 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +fs.readdir('../app/data/zadanie02', (err, files) => { + if (err === null){ + files.forEach(file => { + fs.readFile('../app/data/zadanie02/'+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); +} +}); \ No newline at end of file From ab105fb90ac2c4a554861235783a99d2140b4e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 13:07:28 +0100 Subject: [PATCH 3/6] in progress --- app/zadanieDnia.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..c590dd9 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,25 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +function TrAwKa(fileName) { + fs.readFile(fileName, 'utf8', (err, data) => { + if (err === null) { + let text = data.split(" "); + for (let i = 0; i < text.length; i++){ + text[i] = text[i].split(""); + if (i%0 !== 2) { + text[i][0] = text[i][0].toLowerCase() + } + else { + text[i][0] = text[i][0].toUpperCase(); + } + + text[i] = text[i].join(""); + } + return console.log(text.join(" ")); + + } else { + console.log('Błąd podczas odczytu pliku!', err); + } + }); +} +TrAwKa('../app/data/zadanieDnia/test.txt'); \ No newline at end of file From 9c266b5b3b32900d3a3707cb9bb7a4737595bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 13:21:17 +0100 Subject: [PATCH 4/6] upper and lowerCase in progress --- app/zadanieDnia.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index c590dd9..81054bc 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -22,4 +22,4 @@ function TrAwKa(fileName) { } }); } -TrAwKa('../app/data/zadanieDnia/test.txt'); \ No newline at end of file +TrAwKa(process.argv[2]); From 7186b9cf043ef539bb326b85960962f49874b5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 14:52:40 +0100 Subject: [PATCH 5/6] Challenge 2 done --- app/data/zadanieDnia/test.txt | 10 +++++----- app/zadanieDnia.js | 25 +++++++++---------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 47c17e3..83474ce 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 81054bc..c7e0da3 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -3,23 +3,16 @@ const fs = require('fs'); function TrAwKa(fileName) { fs.readFile(fileName, 'utf8', (err, data) => { if (err === null) { - let text = data.split(" "); - for (let i = 0; i < text.length; i++){ - text[i] = text[i].split(""); - if (i%0 !== 2) { - text[i][0] = text[i][0].toLowerCase() - } - else { - text[i][0] = text[i][0].toUpperCase(); - } - - text[i] = text[i].join(""); - } - return console.log(text.join(" ")); - + let text = ''; + [...data].forEach((e, i) => { + text += (i % 2 === 0) ? e.toUpperCase() : e.toLowerCase(); + }); + fs.writeFile(fileName, text, err => { + err === null? console.log('Plik został zmieniony w nieskoszoną TrAwKę:' +'\n\n'+ text) : console.log('Błąd zapisu pliku') + }) } else { - console.log('Błąd podczas odczytu pliku!', err); + console.log('Błąd odczytu pliku') } }); } -TrAwKa(process.argv[2]); +TrAwKa(process.argv[2]); \ No newline at end of file From 832f12315bfc8d0d927040214d888e56001f9f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20G=C3=B3rzanowska?= Date: Fri, 9 Feb 2018 15:14:16 +0100 Subject: [PATCH 6/6] Challenge 2, second solution --- app/data/zadanieDnia/test.txt | 10 ++++---- app/zadanieDnia.js | 48 ++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 83474ce..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 c7e0da3..d62cc71 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -4,15 +4,49 @@ function TrAwKa(fileName) { fs.readFile(fileName, 'utf8', (err, data) => { if (err === null) { let text = ''; - [...data].forEach((e, i) => { - text += (i % 2 === 0) ? e.toUpperCase() : e.toLowerCase(); - }); - fs.writeFile(fileName, text, err => { - err === null? console.log('Plik został zmieniony w nieskoszoną TrAwKę:' +'\n\n'+ text) : console.log('Błąd zapisu pliku') + for (let i = 0; i < data.length; i++) { + if (i % 2 !== 0) { + + text += data[i].toUpperCase(); + } + else { + text += data[i].toLowerCase(); + } + } + return fs.writeFile(fileName, text, err => { + if (err === null) { + console.log('Plik został zmieniony w nieskoszoną TrAwKę:' + '\n\n' + text); + } else { + console.log("błąd zapisu", err); + } }) } else { - console.log('Błąd odczytu pliku') + console.log('Błąd podczas odczytu pliku!', err); } }); } -TrAwKa(process.argv[2]); \ No newline at end of file + +TrAwKa(process.argv[2]); + +// //version 2: +// const fs = require('fs'); +// function TrAwKa(fileName) { +// fs.readFile(fileName, 'utf8', (err, data) => { +// if (err === null) { +// let text = ''; +// [...data].forEach((e, i) => { +// text += (i % 2 === 0) ? e.toUpperCase() : e.toLowerCase(); +// }); +// fs.writeFile(fileName, text, err => { +// err === null? console.log('Plik został zmieniony w nieskoszoną TrAwKę:' +'\n\n'+ text) : console.log('Błąd zapisu pliku') +// }) +// } else { +// console.log('Błąd odczytu pliku') +// } +// }); +// } +// TrAwKa(process.argv[2]); + + + +