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

Node.js_challenge_dzien_2_done #15

Open
wants to merge 6 commits 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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/data/sum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,2,7,20,56,22
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
10 changes: 5 additions & 5 deletions app/data/zadanieDnia/test.txt
Original file line number Diff line number Diff line change
@@ -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]
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]
26 changes: 25 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
//Twój kod
const fs = require('fs');

fs.readFile('../app/data/zadanie01/input.json', 'utf8', (err, data) => {
if (err === null){
console.log('Poprawnie odczytano plik.', data);
let arr = JSON.parse(data);
function sum (x){
let y= 0;
for (i=0; i<arr.length; i++) {
y +=arr[i];
}
return y;
}
fs.writeFile('../app/data/zadanie01/sum.txt', sum(arr), err => {
if (err === null){
console.log('Zapisano sumę poprawnie!');
} else {
console.log('Błąd podczas zapisu sumy w pliku!', err);
}
});

} else {
console.log('Błąd podczas odczytu pliku jSON!', err);
}
});
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
const fs = require('fs');

fs.readdir('../app/data/zadanie02', (err, files) => {
if (err === null){
files.forEach(file => {
fs.readFile('../app/data/zadanie02/'+file, 'utf8', (err, data) => {
if (err === null){
console.log(data);
} else {
console.log('Błąd podczas odczytu pliku!', err);
}
});


});
} else {
console.log('Błąd podczas listowania katalogu!', err);
}
});
53 changes: 52 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
//Twój kod
const fs = require('fs');

function TrAwKa(fileName) {
fs.readFile(fileName, 'utf8', (err, data) => {
if (err === null) {
let text = '';
for (let i = 0; i < data.length; i++) {
if (i % 2 !== 0) {

text += data[i].toUpperCase();
}
else {
text += data[i].toLowerCase();
}
}
return fs.writeFile(fileName, text, err => {
if (err === null) {
console.log('Plik został zmieniony w nieskoszoną TrAwKę:' + '\n\n' + text);
} else {
console.log("błąd zapisu", err);
}
})
} else {
console.log('Błąd podczas odczytu pliku!', err);
}
});
}

TrAwKa(process.argv[2]);

// //version 2:
// const fs = require('fs');
// function TrAwKa(fileName) {
// fs.readFile(fileName, 'utf8', (err, data) => {
// if (err === null) {
// let text = '';
// [...data].forEach((e, i) => {
// text += (i % 2 === 0) ? e.toUpperCase() : e.toLowerCase();
// });
// fs.writeFile(fileName, text, err => {
// err === null? console.log('Plik został zmieniony w nieskoszoną TrAwKę:' +'\n\n'+ text) : console.log('Błąd zapisu pliku')
// })
// } else {
// console.log('Błąd odczytu pliku')
// }
// });
// }
// TrAwKa(process.argv[2]);