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..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/zadanie01.js b/app/zadanie01.js index 8c20173..c95e494 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,38 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +let read = () => { + + return new Promise((resolve, reject) => { + + fs.readFile('./data/zadanie01/input.json', 'utf-8', (err, data) => { + if (err){ + throw err; + } else { + resolve(data); + } + }); + }); +} + +let sum = (data) => { + + let dataArr = JSON.parse(data); + let sum = 0; + + for(index in dataArr){ + sum += dataArr[index] + } + return sum; +} + +let write = (sum) => { + + fs.writeFile('./data/zadanie01/sum.txt', sum, (err) => { + if (err) throw err; + }); + +} + +read() +.then((data) => { return sum(data) }) +.then((sum) => { write(sum) } ); diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..4a611b3 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,38 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +let read = () => { + + return new Promise((resolve, reject) => { + + fs.readdir('./data/zadanie02/', (err, files) => { + if (err === null){ + resolve(files) + } else { + throw err; + } + }); + }); +} + +let content = (files) => { + files.forEach(file => { + getContent(file); + }); +} + +let getContent = (file) => { + + let fileDir = `./data/zadanie02/${file}` + + fs.readFile(fileDir, 'utf-8', (err, data) => { + if (err){ + throw err; + } else { + console.log(data); + } + }); + +} + +read().then((data) => { content(data) }) + diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..de16184 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,52 @@ -//Twój kod \ No newline at end of file +const fs = require('fs'); + +let read = (filePath) => { + + return new Promise((resolve, reject) => { + + fs.readFile(filePath, 'utf-8', (err, data) => { + if (err === null){ + resolve(data) + } else { + throw err; + } + }); + }); +} + +let camelWords = (text) => { + + let allText = ''; + + for(letter in text){ + if(letter % 2 === 0){ + allText += text[letter].toUpperCase(); + } else { + allText += text[letter]; + } + } + + return allText; +} + +let saveText = (filePath, text) => { + + fs.writeFile(filePath, text, (err) => { + if (err) throw err; + }); + +} + +let filePath = ''; + +process.argv.forEach((val, index) => { + + if(index === 2){ + filePath = val; + + read(filePath) + .then((data) => { return camelWords(data) } ) + .then((text) => { saveText(filePath, text) } ); + }; + +}); \ No newline at end of file