From 745ca267177f815129bb239cae1667f184518d55 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Feb 2019 15:35:29 +0100 Subject: [PATCH 1/3] first task complete --- app/data/zadanie01/sum.txt | 1 + app/zadanie01.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) 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..6db6a6e 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 dupa = JSON.parse(data); + + console.log(`zmienna: ${dupa[2]} typu: ${typeof dupa[2]}`) + + const sum = dupa.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 popranie!'); + } 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 From ab562f086ee6f8a84020efa679d5c1d657ce43fe Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Feb 2019 16:03:30 +0100 Subject: [PATCH 2/3] task02 complete --- app/zadanie02.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 From 1333657f61d1bca26c8653962ff898aebc7d99e2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Feb 2019 21:09:36 +0100 Subject: [PATCH 3/3] task of the dat complete --- app/zadanie01.js | 8 ++++---- app/zadanieDnia.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 6db6a6e..13a9028 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -7,18 +7,18 @@ fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => { console.log('two') // 3 console.log(`Poprawnie odczytano plik. typu ${typeof data}: `, data); - const dupa = JSON.parse(data); + const paresData = JSON.parse(data); - console.log(`zmienna: ${dupa[2]} typu: ${typeof dupa[2]}`) + console.log(`zmienna: ${paresData[2]} typu: ${typeof paresData[2]}`) - const sum = dupa.reduce((acc, cur) => { + 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 popranie!'); + console.log('zapisano poprawnie!'); } else { console.log(' Błąd podczas zapisu pliku!', err); } 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