From 3e427cc9d27a06f405972eb4fbd64742a3b76a7f Mon Sep 17 00:00:00 2001 From: Maciej Judka Date: Tue, 30 Jan 2018 17:31:11 +0100 Subject: [PATCH 1/5] Add zadanie01 --- app/data/zadanie01/sum.txt | 1 + app/zadanie01.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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..9e9c50e 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,11 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +fs.readFile('./data/zadanie01/input.json', 'utf-8', (err, data) => { + if (err) return console.log('Błąd odczytu pliku!'); + + let sum = JSON.parse(data).reduce((x, y) => x + y); + + fs.writeFile('./data/zadanie01/sumss.txt', sum, err => { + if (err) return console.log('Błąd zapisu pliku!') + }); +}); \ No newline at end of file From af03ca1d1b02058884bb24015c46a2d57502cb68 Mon Sep 17 00:00:00 2001 From: Maciej Judka Date: Tue, 30 Jan 2018 17:35:14 +0100 Subject: [PATCH 2/5] Update zadanie01 --- app/zadanie01.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 9e9c50e..a160cc3 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -5,7 +5,8 @@ fs.readFile('./data/zadanie01/input.json', 'utf-8', (err, data) => { let sum = JSON.parse(data).reduce((x, y) => x + y); - fs.writeFile('./data/zadanie01/sumss.txt', sum, err => { - if (err) return console.log('Błąd zapisu pliku!') + fs.writeFile('./data/zadanie01/sum.txt', sum, err => { + let msg = err ? 'Błąd zapisu pliku' : 'Plik poprawnie zapisany'; + return console.log(msg) }); }); \ No newline at end of file From 8f6bbefc83b87cd848c7c432624025619b23e998 Mon Sep 17 00:00:00 2001 From: Maciej Judka Date: Tue, 30 Jan 2018 18:12:11 +0100 Subject: [PATCH 3/5] Add zadanie02 --- app/zadanie02.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..acbffd6 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,14 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +let path = './data/zadanie02/'; + +fs.readdir(path, (err, files) => { + if (err) return console.log('Błąd odczytu katalogu'); + + files.forEach(file => { + console.log(`Nazwa pliku: ${file}`); + let data = fs.readFileSync(`${path}${file}`); + console.log(data.toString()); + console.log(`-----------------------------`); + }); +}); \ No newline at end of file From 9566712d60be75bb75152886629b6e32d097a1b2 Mon Sep 17 00:00:00 2001 From: Maciej Judka Date: Tue, 30 Jan 2018 18:37:19 +0100 Subject: [PATCH 4/5] Add zadanieDnia --- app/zadanieDnia.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..e2b0f64 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,17 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +const path = process.argv.slice(2).toString(); + +let trawka = (path) => { + fs.readFile(path, 'utf-8', (err, data) => { + if (err) return console.log('Błąd odczytu pliku'); + + let newData = [...data].map((elem, i) => { + return i % 2 === 0 ? elem.toUpperCase() : elem + }) + + console.log(newData.join('')) + }); +}; + +trawka(path) \ No newline at end of file From 70b8ea225bbc394a8152118e172a68d993440247 Mon Sep 17 00:00:00 2001 From: Maciej Judka Date: Tue, 30 Jan 2018 18:44:56 +0100 Subject: [PATCH 5/5] Update zadanieDnia --- app/data/zadanieDnia/test.txt | 10 +++++----- app/data/zadanieDnia/test_temp.txt | 7 +++++++ app/zadanieDnia.js | 5 +++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 app/data/zadanieDnia/test_temp.txt diff --git a/app/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 47c17e3..7a82b9b 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/data/zadanieDnia/test_temp.txt b/app/data/zadanieDnia/test_temp.txt new file mode 100644 index 0000000..47c17e3 --- /dev/null +++ b/app/data/zadanieDnia/test_temp.txt @@ -0,0 +1,7 @@ +You Don't Know JS: ES6 & Beyond +Foreword + +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 diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index e2b0f64..36ccf8e 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -11,6 +11,11 @@ let trawka = (path) => { }) console.log(newData.join('')) + + fs.writeFile(path, newData.join(''), err => { + let msg = err ? 'Błąd zapisu pliku' : 'Plik poprawnie zapisany'; + return console.log(msg); + }) }); };