diff --git a/app/data/file.txt b/app/data/file.txt new file mode 100644 index 0000000..b45ef6f --- /dev/null +++ b/app/data/file.txt @@ -0,0 +1 @@ +Hello, World! \ 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/data/zadanieDnia/test.txt b/app/data/zadanieDnia/test.txt index 47c17e3..315424d 100644 --- a/app/data/zadanieDnia/test.txt +++ b/app/data/zadanieDnia/test.txt @@ -4,4 +4,4 @@ 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 +[https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20%26%20beyond/foreword.md] diff --git a/app/data/zadanieDnia/test2.txt b/app/data/zadanieDnia/test2.txt new file mode 100644 index 0000000..f7a3d88 --- /dev/null +++ b/app/data/zadanieDnia/test2.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] diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..8c84e1e 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,18 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); +const path = './data/zadanie01'; +fs.readFile(`${path}/input.json`, 'utf8', (error, data) => { + if (error) { + console.error('Błąd podczas odczytu pliku!', error); + } else { + const arrayOfNumbers = JSON.parse(data); + let arraySum = 0; + arrayOfNumbers.forEach((value) => arraySum += value); + fs.writeFile(`${path}/sum.txt`, arraySum, err => { + if (err === null){ + console.info('Zapisano poprawnie!'); + } else { + console.error('Błąd podczas zapisu pliku!', err); + } + }); + } +}); diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..45dafbd 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,12 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +fs.readdir('./data/zadanie02', (err, files) => { + if (err === null){ + console.log('Lista plików:'); + files.forEach(file => { + console.log(file); + }); + } else { + console.log('Błąd podczas listowania katalogu!', err); + } +}); diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..92666ce 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,23 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +const fileName = process.argv[2]; +const path = `./data/zadanieDnia/${fileName}`; + +fs.readFile(path, 'utf8', (error_read, data) => { + if (error_read === null){ + let content = ''; + for (let i = 0; i < data.length; i += 1){ + console.log('znak data[i] =', data[i]); + content += (i % 2 === 0) ? data[i].toUpperCase() : data[i].toLowerCase(); + } + fs.writeFile(`./data/zadanieDnia/test2.txt`, content, error_write => { + if (error_write === null){ + console.log('zapisno plik.'); + } else { + console.log('blad zapisu:', error_write); + } + }); + } else { + console.log('nie udalo sie odczytac pliku =', error_read); + } +});