diff --git a/app/data/zadanie01/sum.txt b/app/data/zadanie01/sum.txt index e69de29..f5cd371 100644 --- a/app/data/zadanie01/sum.txt +++ b/app/data/zadanie01/sum.txt @@ -0,0 +1 @@ +sum of numbers from task 01 is: 108 \ No newline at end of file diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..13a9028 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,36 @@ -//Twój kod \ No newline at end of file +//Twój kod +const fs = require('fs'); +console.log('one') //1 + +fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => { + if (err === null) { + console.log('two') // 3 + console.log(`Poprawnie odczytano plik. typu ${typeof data}: `, data); + + const paresData = JSON.parse(data); + + console.log(`zmienna: ${paresData[2]} typu: ${typeof paresData[2]}`) + + const sum = paresData.reduce((acc, cur) => { + return acc + cur; + }) + console.log(`sum of numbers: ${sum}`) + + fs.writeFile('./data/zadanie01/sum.txt', `sum of numbers from task 01 is: ${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); + } + console.log('three') //4 +}); +console.log('four') //2 \ No newline at end of file diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..b30b94a 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,13 @@ -//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){ + console.log('lista plików:'); + files.forEach(file => { + console.log(file); + }); + } else { + console.log('Błąd podczas listowania katalogu!', err); + } +}); \ No newline at end of file diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..d7999be 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,29 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const arg = process.argv[2]; +const fs = require('fs'); + +if(!arg){ + console.log('give some arg please!') +}else{ + console.log(`mutch better: ${arg}`) + fs.readFile(arg, 'utf8', (err, data) => { + if (err === null) { + console.log('poprawnie odczytano plik: ', typeof data, data.length); + const str = data; + const lowStr = str.toLowerCase(); + let newStr = ''; + + for (i = 0; i < lowStr.length; i++) { + if (i % 2 == 0) { + newStr += lowStr[i].toUpperCase() + } else { + newStr += lowStr[i] + } + } + console.log(newStr) + } else { + console.log('Błąd podczas odczytu plik!', err); + } + }); +} \ No newline at end of file