Conversation
Siusarna
left a comment
There was a problem hiding this comment.
Good job. Pls, see comments.
| if (mode === 'weather') { | ||
| const dData = makeWeatherData(data); | ||
| dData.city = data.name; | ||
| wData.push(dData); |
There was a problem hiding this comment.
I think it would be better to create a "processingData" function and just call it in both situations
|
|
||
| function saveRecent (city) { | ||
| const recent = readRecent(); | ||
| if (recent.indexOf(city) === -1) { |
There was a problem hiding this comment.
You can use recent.includes(city) for determines whether an array includes a certain value
|
|
||
| const fs = require('fs'); | ||
|
|
||
| function saveRecent (city) { |
There was a problem hiding this comment.
You can remove nested in this function, if by using negative check and then return
There was a problem hiding this comment.
Ah, I can't see how. I need to remove the last record from recent if there are more then 9 records and save the changes anyway. If I return the saving will be skipped.
I have removed the nested if another way.
There was a problem hiding this comment.
I may be writing not-working code, but if it works, then its solution would be better
| function saveRecent (city) { | |
| function saveRecent (city) { | |
| const recent = readRecent(); | |
| if(!recent.includes(city)) return; | |
| recent.unshift(city); | |
| if (recent.lenght > 9) recent.pop(); | |
| writeRecent(recent); | |
| } |
There was a problem hiding this comment.
So I have done. One thing: not
if(!recent.includes(city)) return
but
if(recent.includes(city)) return
because we add a new city to recent if it is not in the list
Actually I'm not sure, that it is correct to do so, because thus we make code somewhat shorter but, in my opinion less readable. This can make some sense in browser js where shorter code means less traffic, but in server node.js code it makes no sense. IMHO.
But there is another problem. Semistandard finds an error in my code, but the error message encoding is a mess and I can not get where the error is. The semistandard extension for my VS Code shows no linter errors.
| } | ||
|
|
||
| function readFavorite () { | ||
| if (fs.existsSync('favorite.csv')) { |
There was a problem hiding this comment.
You can remove nested if by using negative check and then return
|
|
||
| function writeFavorite (favorite) { | ||
| fs.writeFile('favorite.csv', favorite.map(c => { | ||
| return `${c.name};${c.count}`; |
There was a problem hiding this comment.
| return `${c.name};${c.count}`; | |
| favorite.map(c => `${c.name};${c.count}`) |
| data.name); | ||
| saveCities(location); | ||
| }).catch(error => { | ||
| if ((error.response.data || {}).message === 'city not found' || (error.response.data || {}).message === 'Nothing to geocode') { |
There was a problem hiding this comment.
I think it would be better if you write const message = (error.response.data || { }).message; and then use message variable in if-else block
Name your PR following the template:
Add <taskname> by <your github username>and remove this paragraph.I've read
./README.mdand./CODE_QUALITY.mdcarefully.The code is checked by
yarn run lint:jsand linter reported no errors.The code is submitted in its own sub-directory and in a dedicated feature branch.
Please, review.