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/data/zadanieDnia/result.txt b/app/data/zadanieDnia/result.txt new file mode 100644 index 0000000..83474ce --- /dev/null +++ b/app/data/zadanieDnia/result.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/zadanie01.js b/app/zadanie01.js index 8c20173..b2a2ee3 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", "utf-8", (err, data) => { + if (err === null){ + let sum = 0; + JSON.parse(data).forEach(a => sum += a); + fs.writeFile("./data/zadanie01/sum.txt", sum, err => { + if (err === null) { + console.log("Zapisano wynik!"); + } + else { + console.log('Błąd podczas zapisu pliku!', err); + } + }); + } + else { + console.log('Błąd podczas odczytu pliku!', err); + } +}); \ No newline at end of file diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..5e9382e 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,26 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const fs = require("fs"); +const dir = "./data/zadanie02/"; + +fs.readdir(dir, (err, files) => { + if (err === null) { + files.forEach(file => readFile(dir+file)); + } + else { + console.log("Nie udało się przeczytać katalogu: " + err); + } + +}); + + +function readFile(file) { + fs.readFile(file, "utf-8", (err, data) => { + if (err === null) { + console.log(data); + } + else { + console.log("Nie udało się odczytac pliku: " + file + "! " + err); + } + }); +} \ No newline at end of file diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..da1ce42 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,28 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const fs = require("fs"); +const file = process.argv[2]; + +if (typeof file === 'undefined') { + console.log("Wymagany parametr!"); + process.exit(1); +} + +fs.readFile(file, 'utf-8', (err, data) => { + if ((err === null)) { + let result = ''; + data.split('').forEach((letter, index) => { (index % 2 === 0) ? result += letter.toUpperCase() : result += letter.toLowerCase(); }); + + fs.writeFile("./data/zadanieDnia/result.txt", result, err => { + if (err === null) { + console.log("Zapisano wynik!"); + } + else { + console.log('Błąd podczas zapisu pliku!', err); + } + }) + } + else { + console.log(err); + } +});