Skip to content
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
17 changes: 16 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
//Twój kod
const fs = require('fs');

fs.readFile('./data/zadanie01/input.json', 'utf8', (err, data) => {
if (err === null) {
let sum = JSON.parse(data).reduce(((acc, val) => acc + val), 0);
fs.writeFile('./data/zadanie01/sum.txt', sum, err => {
if (err === null) {
console.log('Poprawnie odczytano i zapisano plik. Suma to:', sum);
} else {
console.log('Błąd podczas zapisu pliku!', err);
}
});
} else {
console.log('Błąd podczas odczytu pliku!', err);
}
});
18 changes: 17 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
//Twój kod
const fs = require('fs');

fs.readdir('./data/zadanie02', (err, files) => {
if (err === null) {
files.forEach(file => {
fs.readFile('./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);
}
});
22 changes: 21 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
//Twój kod
const fs = require('fs');

fs.writeFileSync('./copy.txt', fs.readFileSync(process.argv[2]));

fs.readFile(process.argv[2], 'utf8', (err, data) => {
if (err === null) {
let newText = "";
for (let i = 0; i < data.length; i++) {
newText += (i % 2 === 0) ? data[i].toUpperCase() : data[i].toLowerCase();
}
fs.writeFile(process.argv[2], newText, err => {
if (err === null) {
console.log('Poprawnie odczytano i zapisano zmieniony plik');
} else {
console.log('Błąd podczas zapisu pliku!', err);
}
});
} else {
console.log('Błąd podczas odczytu pliku!', err);
}
});