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

fun with JS #2 #2

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
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/result.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]
22 changes: 21 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
//Twój kod
//Twój kod

const fs = require("fs");

fs.readFile("./data/zadanie01/input.json", "utf-8", (err, data) => {
if (err === null){
let sum = 0;
JSON.parse(data).forEach(a => sum += a);
fs.writeFile("./data/zadanie01/sum.txt", sum, err => {
if (err === null) {
console.log("Zapisano wynik!");
}
else {
console.log('Błąd podczas zapisu pliku!', err);
}
});
}
else {
console.log('Błąd podczas odczytu pliku!', err);
}
});
27 changes: 26 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
//Twój kod
//Twój kod

const fs = require("fs");
const dir = "./data/zadanie02/";

fs.readdir(dir, (err, files) => {
if (err === null) {
files.forEach(file => readFile(dir+file));
}
else {
console.log("Nie udało się przeczytać katalogu: " + err);
}

});


function readFile(file) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super. Na pewno czytelniejsza jest osobna funkcja.

fs.readFile(file, "utf-8", (err, data) => {
if (err === null) {
console.log(data);
}
else {
console.log("Nie udało się odczytac pliku: " + file + "! " + err);
}
});
}
29 changes: 28 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
//Twój kod
//Twój kod

const fs = require("fs");
const file = process.argv[2];

if (typeof file === 'undefined') {
console.log("Wymagany parametr!");
process.exit(1);
}

fs.readFile(file, 'utf-8', (err, data) => {
if ((err === null)) {
let result = '';
data.split('').forEach((letter, index) => { (index % 2 === 0) ? result += letter.toUpperCase() : result += letter.toLowerCase(); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fajny pomysł :)


fs.writeFile("./data/zadanieDnia/result.txt", result, err => {
if (err === null) {
console.log("Zapisano wynik!");
}
else {
console.log('Błąd podczas zapisu pliku!', err);
}
})
}
else {
console.log(err);
}
});