-
Notifications
You must be signed in to change notification settings - Fork 252
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
MJ - Day2 #3
base: master
Are you sure you want to change the base?
MJ - Day2 #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
108 |
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] |
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] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
//Twój kod | ||
const fs = require('fs'); | ||
|
||
fs.readFile('./data/zadanie01/input.json', 'utf-8', (err, data) => { | ||
if (err) return console.log('Błąd odczytu pliku!'); | ||
|
||
let sum = JSON.parse(data).reduce((x, y) => x + y); | ||
|
||
fs.writeFile('./data/zadanie01/sum.txt', sum, err => { | ||
let msg = err ? 'Błąd zapisu pliku' : 'Plik poprawnie zapisany'; | ||
return console.log(msg) | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
//Twój kod | ||
const fs = require('fs'); | ||
|
||
let path = './data/zadanie02/'; | ||
|
||
fs.readdir(path, (err, files) => { | ||
if (err) return console.log('Błąd odczytu katalogu'); | ||
|
||
files.forEach(file => { | ||
console.log(`Nazwa pliku: ${file}`); | ||
let data = fs.readFileSync(`${path}${file}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Staramy się zawsze używać funkcji asynchronicznych - dlatego tylko takie poznaliśmy. Dzięki temu kiedy Node.js "nudzi się" odczytem pliku - mogą się dziać inne rzeczy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tak racja. Chciałem tym uzyskać odczyt pliku pod nazwą pliku bez rejestrowania eventu :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jasna sprawa :) Wygląda "prościej", ale właśnie nie korzysta z tej przewagi Node. |
||
console.log(data.toString()); | ||
console.log(`-----------------------------`); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
//Twój kod | ||
const fs = require('fs'); | ||
|
||
const path = process.argv.slice(2).toString(); | ||
|
||
let trawka = (path) => { | ||
fs.readFile(path, 'utf-8', (err, data) => { | ||
if (err) return console.log('Błąd odczytu pliku'); | ||
|
||
let newData = [...data].map((elem, i) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Najlepszy sposób. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dziękuję :) |
||
return i % 2 === 0 ? elem.toUpperCase() : elem | ||
}) | ||
|
||
console.log(newData.join('')) | ||
|
||
fs.writeFile(path, newData.join(''), err => { | ||
let msg = err ? 'Błąd zapisu pliku' : 'Plik poprawnie zapisany'; | ||
return console.log(msg); | ||
}) | ||
}); | ||
}; | ||
|
||
trawka(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Dodatkowo, można było użyć
const
.