Skip to content

Conversation

@kzemlyak
Copy link
Contributor

  • Uses more undrestandable variable names
  • Uses for loop instead of forEach

- Uses more undrestandable variable names - Uses for loop instead of forEach
Copy link
Member

@tshemsedinovtshemsedinov left a comment

Choose a reason for hiding this comment

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

  • Use camelCase: fileName
  • Here is a case for .map

@kzemlyak
Copy link
ContributorAuthor

  • Here is a case for .map

But if we use map in this case, wouldn't it be semantically incorrect because there will be mutation of the external variable (stats) inside map, while map is intended for immutable behavior?

@tshemsedinov
Copy link
Member

But if we use map in this case, wouldn't it be semantically incorrect because there will be mutation of the external variable (stats) inside map, while map is intended for immutable behavior?

You can easily do it without mutations. Reflect array of names to array of stats, we do not even need counters, printResult, and isLastProcessed here.

@kzemlyak
Copy link
ContributorAuthor

But for that, I will need to use Promises to do this. Can I use them in this example?

@tshemsedinov
Copy link
Member

constpromises=files.map((fileName)=>fs.lstat(fileName));Promise.allSettled(promises).then((stats)=>{console.dir(stats);});

@kzemlyak
Copy link
ContributorAuthor

I just thought that it's not worth using Promises in this example since they were not originally included

@tshemsedinov
Copy link
Member

We can refactor this even without promises, using closures, I'll provide multiple solutions a bit later

@tshemsedinovtshemsedinov merged commit 1fd0f32 into HowProgrammingWorks:masterJul 13, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@kzemlyak@tshemsedinov