Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dzień 2 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const fs = require('fs');
//Zapisz plik...
fs.writeFile('./data/file.txt', 'Hello, World!', err => {//Zapis: ...kiedy skończysz uruchom naszą funkcję callback
if (err === null){ //Zapis: Sprawdzamy czy obiekt błędu jest null-em - jeżeli tak - wszystko poszło ok

//Odczytaj plik...
fs.readFile('./data/file.txt', 'utf8', (err, data) => {//Odczyt: ...kiedy skończysz uruchom naszą funkcję callback
if (err === null){ //Odczyt: Sprawdzamy czy obiekt błędu jest null-em - jeżeli tak - wyświetlamy zawartość pliku
Expand All @@ -179,7 +179,7 @@ fs.writeFile('./data/file.txt', 'Hello, World!', err => {//Zapis: ...kiedy skoń
console.log('Błąd podczas odczytu pliku!', err);
}
});

} else { //Zapis: Jeżeli obiekt błędu nie był null-em, to pojawił się błąd - np. niepoprawna ścieżka
console.log('Błąd podczas zapisu pliku!', err);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ LISTOWANIE ZAWARTOŚCI KATALOGU
KIEDY SKOŃCZY - CALLBACK:
PĘTLA DLA KAŻDEJ NAZWY PLIKU
ODCZYT PLIKU
KIERY SKOŃCZY - CALLBACK:
KIEDY SKOŃCZY - CALLBACK:
WYŚWIETLENIE ZAWARTOŚCI PLIKU LUB INFORMACJI BŁĘDZIE
```

Expand All @@ -295,7 +295,7 @@ ODCZYT PLIKU
KIEDY SKOŃCZY - CALLBACK:
ZMIANA TEKSTU WEDŁUG WZORU
ZAPIS TAKIEGO SAMEGO PLIKU
KIERY SKOŃCZY - CALLBACK:
KIEDY SKOŃCZY - CALLBACK:
INFORMACJA O POWODZENIU LUB BŁĘDZIE
```

Expand All @@ -313,4 +313,4 @@ node zadanieDnia.js ./data/zadanieDnia/test.txt
[forking]: https://guides.github.com/activities/forking/
[ref-clone]: http://gitref.org/creating/#clone
[es6-tutorial]: http://qnimate.com/post-series/ecmascript-6-complete-tutorial/
[download-node]: https://nodejs.org/en/download/
[download-node]: https://nodejs.org/en/download/
1 change: 1 addition & 0 deletions app/data/zadanie01/sum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
108
7 changes: 7 additions & 0 deletions app/data/zadanieDnia/c_test.txt
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 7 additions & 0 deletions app/data/zadanieDnia/copy_test.txt
Original file line number Diff line number Diff line change
@@ -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]
20 changes: 19 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
//Twój kod
//Twój kod

const fs = require('fs');

fs.readFile('./data/zadanie01/input.json',(err,data) => {
if (err == null){
let dane = JSON.parse(data);
let result = dane.reduce((prev,next) => prev+next);
fs.writeFile('./data/zadanie01/sum.txt',result,err => {
if(err == null){
console.log('Zapis do pliku zakończony powdzeniem');
} else {
console.log('Błąd zapisu pliku');
}
});
} else {
console.log('Błąd odczytu danych');
}
});
20 changes: 19 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
//Twój kod
//Twój kod
const fs = require('fs');

fs.readdir('./data/zadanie02',(err,files) => {
if (err === null){
files.forEach((file) => {
//console.log(file);
fs.readFile('./data/zadanie02/'+file,'UTF-8',(err,data) => {
if (err === null){
console.log(data);
} else {
console.log(`Błąd odczytu pliku`);
}
});
});
} else {
console.log('Błąd odczytu listy plików');
}
});
39 changes: 38 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
//Twój kod
//Twój kod
const fs = require('fs');

let [element,index,fileName] = [...process.argv];

fs.readFile('./data/zadanieDnia/'+fileName,'UTF-8',(err,data) => {
if (err === null){

let textData = [...data];

fs.writeFile('./data/zadanieDnia/copy_'+fileName,data,err => {
//tworzenie kopii zapasowej

if (err === null){

let textChanged = textData.map((element,index) => {

if (!(index % 2)) {
return element.toUpperCase();
} else {
return element.toLowerCase();
}
});

fs.writeFile('./data/zadanieDnia/c_'+fileName,textChanged.join(''),err => {
if (err ===null) {
console.log('Zapis zakończył się sukcesem');
}
});

} else {
console.log('Błąd tworzenia kopii zapasowej');
}
});
} else {
console.log('Błąd odczytu pliku');
}
});