From 9bf3d9ac17b1eca15138b2af8732d106b43be6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Tue, 30 Jan 2018 21:39:54 +0100 Subject: [PATCH 1/8] Zadanie 01 - done --- app/zadanie01.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..997cbde 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){ + console.log('Poprawnie odczytano plik.', data); + let arrParsed = JSON.parse(data); + let sum = arrParsed.reduce( (prev, curr) => { return prev + curr } ); + + fs.writeFile('./data/zadanie01/sum.txt', sum, err => { + if (err === null){ + console.log('Zapisano poprawnie!'); + } 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 b98f092b376ddb9de4ea8026f4246326bfa85a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Tue, 30 Jan 2018 21:40:12 +0100 Subject: [PATCH 2/8] Zadanie 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..b5ef582 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const fs = require('fs'); + +fs.readdir('./data/zadanie02', (err, files) => { + if (err === null){ + files.forEach(file => { + fs.readFile(`./data/zadanie02/${file}`, 'utf8', (err, data) => { + if (err === null){ + console.log(`Poprawnie odczytano plik ${file}. Jego zawartość to: `, 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 0d03895dd4baa29b02df326c2090411396b8dcfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Tue, 30 Jan 2018 21:41:17 +0100 Subject: [PATCH 3/8] Zadanie 01 - done --- app/data/zadanie01/sum.txt | 1 + 1 file changed, 1 insertion(+) 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 From 4abac0630ce5eada86e09ebbd1a693e0ca8f360c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Wed, 31 Jan 2018 11:47:27 +0100 Subject: [PATCH 4/8] Zadanie 01 - done --- app/zadanie01.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 997cbde..f95535b 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -4,13 +4,12 @@ const fs = require('fs'); fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => { if (err === null){ - console.log('Poprawnie odczytano plik.', data); let arrParsed = JSON.parse(data); let sum = arrParsed.reduce( (prev, curr) => { return prev + curr } ); fs.writeFile('./data/zadanie01/sum.txt', sum, err => { if (err === null){ - console.log('Zapisano poprawnie!'); + console.log('Poprawnie odczytano i zapisano plik! Suma wynosi: ', sum); } else { console.log('Błąd podczas zapisu pliku!', err); } From a7a7e2a5b1bd056136d999d483a36bc4222ab101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Wed, 31 Jan 2018 11:49:11 +0100 Subject: [PATCH 5/8] Zadanie 02 - done --- app/zadanie02.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index b5ef582..b96a273 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -4,7 +4,7 @@ const fs = require('fs'); fs.readdir('./data/zadanie02', (err, files) => { if (err === null){ - files.forEach(file => { + files.forEach( file => { fs.readFile(`./data/zadanie02/${file}`, 'utf8', (err, data) => { if (err === null){ console.log(`Poprawnie odczytano plik ${file}. Jego zawartość to: `, data); From a3befae623173c204d0255b901ecb1faf98e4352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Wed, 31 Jan 2018 11:50:03 +0100 Subject: [PATCH 6/8] ZadanieDnia - done --- app/zadanieDnia.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..a329f36 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,24 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const fs = require('fs'); + +const textFile = process.argv[2]; + +fs.readFile(textFile, 'utf8', (err, data) => { + if (err === null){ + let trawkaText = ""; + data.split("").map( (elem, index) => { + trawkaText += (index % 2 === 0) ? elem.toUpperCase() : elem.toLowerCase(); + }); + + fs.writeFile(textFile, trawkaText, err => { + if (err === null){ + console.log('Poprawnie odczytano i zapisano plik'); + } else { + console.log('Błąd podczas zapisu pliku!', err); + } + }); + } else { + console.log('Błąd podczas odczytu pliku!', err); + } +}); From 5e6cacf4c585f2a3302fb17be1ad7953ccc5bba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Wed, 31 Jan 2018 11:50:45 +0100 Subject: [PATCH 7/8] trawkaText --- app/data/zadanieDnia/test.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 47c17e3..c762954 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, NoTsHoUlD. 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 From 036f673180a761eb397854f64a0303b86fae89d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Wed, 31 Jan 2018 19:06:44 +0100 Subject: [PATCH 8/8] changed let to const --- app/zadanie01.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index f95535b..ea5b22f 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -4,8 +4,8 @@ const fs = require('fs'); fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => { if (err === null){ - let arrParsed = JSON.parse(data); - let sum = arrParsed.reduce( (prev, curr) => { return prev + curr } ); + const arrParsed = JSON.parse(data); + const sum = arrParsed.reduce( (prev, curr) => { return prev + curr } ); fs.writeFile('./data/zadanie01/sum.txt', sum, err => { if (err === null){