diff --git a/app/data/zadanie01/sum.txt b/app/data/zadanie01/sum.txt index e69de29..615088b 100644 --- a/app/data/zadanie01/sum.txt +++ b/app/data/zadanie01/sum.txt @@ -0,0 +1 @@ +108 \ No newline at end of file diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..1d0fdab 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +const fs = require("fs"); + +fs.readFile("./app/data/zadanie01/input.json", (err, data) => { + if (err === null) { + const parsed = JSON.parse(data); + const sum = parsed.reduce((prev, curr) => { + return prev + curr; + }); + fs.writeFile("./app/data/zadanie01/sum.txt", sum, err => { + if (err === null) { + console.log("Zapisano elegancko"); + } else { + console.log("Coś nie pykło z tym zapisaniem"); + } + }); + } else { + console.log("Coś nie bangla"); + } +}); diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..d08ef46 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,19 @@ -//Twój kod \ No newline at end of file +const fs = require("fs"); + +fs.readdir("./app/data/zadanie02", (err, files) => { + if (err === null) { + console.log("Działa ok, oto lista plików: "); + files.forEach(file => { + console.log(file); + fs.readFile(`./app/data/zadanie02/${file}`, "utf8", (err, data) => { + if (err === null) { + console.log(data); + } else { + console.log("Coś chyba z tym readFilem :/"); + } + }); + }); + } else { + console.log("Nie bangla :/"); + } +});