Skip to content

Comments

Avoid classical for when looping through all items of an Array-like object (part #2)#19405

Merged
Josh-Cena merged 107 commits intomdn:mainfrom
teoli2003:fix-classical-for-2
Sep 2, 2022
Merged

Avoid classical for when looping through all items of an Array-like object (part #2)#19405
Josh-Cena merged 107 commits intomdn:mainfrom
teoli2003:fix-classical-for-2

Conversation

@teoli2003
Copy link
Contributor

Classical for loops are error-prone (setting the right condition, not mixing indices…) and difficult to read when used to loop on all elements of an Array-like structure.

This PR changes some occurrences to use the modern for…of, or .forEach() in some occurrences.

Note that:

  • I use for…of if I don't need the index
  • I use .forEach() when I do, or on an object where for…of may not work.
  • There were a couple of cases where the loop copied an Array into a new one; I used Array.from() instead.

@teoli2003 teoli2003 requested a review from a team as a code owner August 11, 2022 10:01
@teoli2003 teoli2003 requested review from a team, Josh-Cena, jpmedley and sideshowbarker and removed request for a team, jpmedley and sideshowbarker August 11, 2022 10:01
@github-actions github-actions bot added the Content:WebAPI Web API docs label Aug 11, 2022
@github-actions

This comment was marked as resolved.

@teoli2003 teoli2003 changed the title Avoid classical for if for...of when looping all object of an Array-like object (part #2) Avoid classical for when looping through all items of an Array-like object (part #2) Aug 11, 2022
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Not a thorough review; would go over this again after the initial reviews are addressed

@teoli2003 teoli2003 requested review from Josh-Cena and removed request for rubiesonthesky August 23, 2022 12:51
@teoli2003 teoli2003 requested a review from Josh-Cena August 24, 2022 10:45
@teoli2003
Copy link
Contributor Author

teoli2003 commented Aug 25, 2022

@Josh-Cena When you have time, can you double-check this PR? I think I have fixed all the review comments.

@Josh-Cena
Copy link
Member

Josh-Cena commented Aug 26, 2022

Sorry for being a little slow. My academic life is picking up and I don't always have access to a computer this week. This PR has a lot of moving parts and reviewing takes some mental energy. I'll try setting aside some time tomorrow.

@teoli2003
Copy link
Contributor Author

Sorry for being a little slow. My academic life is picking up and I don't always have access to a computer this week. This PR has a lot of moving parts and reviewing takes some mental energy. I'll try setting aside some time tomorrow.

No worry, I guessed your academic life started again. Take your time.

@rubiesonthesky
Copy link
Contributor

I have no further comments. I don't know enough of some of the code examples to be able to review if they are correct or not, though they seem good for me.

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Sorry for being so slow to get to this. This looks great to me (had to go through a lot of code that looks almost the same...)

@Josh-Cena Josh-Cena merged commit 24f9f75 into mdn:main Sep 2, 2022
goshdarnheck pushed a commit to goshdarnheck/content that referenced this pull request Sep 7, 2022
…bject (part mdn#2) (mdn#19405)

* Avoid classical for if for...of when looping all object of an Array-like object

* Remove addictions from MDN

* Add checkPerformanceEntry

* Use same example

* Use same example

* Fix naming

* Fix names

* Fix name

* Fix name

* Fix name

* Fix name

* Rename function

* Rename function

* Fix name

* Fix name

* Remove useless const

* Remove useless variable

* fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Fix name

* Remove useless variable

* Remove useless variable

* Remove useless variable

* Remove useless varaible

* Rename function

* fix function name

* Fix function name

* Fix function name

* Fix function name

* Add empty line

* Fix function names

* Update files/en-us/web/api/performanceresourcetiming/decodedbodysize/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Fix function names

* Fix function name

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* fix function names

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* Fix function names

* Use ternary operator

* Fix function names

* Use method

* Update files/en-us/web/api/texttrack/mode/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance/getentriesbytype/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/performance_timeline/using_performance_timeline/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Update files/en-us/web/api/speechsynthesisvoice/name/index.md

Co-authored-by: rubiesonthesky <[email protected]>

* Readd example

* readd example

* Add workerStart to the list

* Replace for…in

* Use findIndex()

* Use findIndex()

* Fix function names (no _)

* Fix alignement + for…in

* Alignment

* Update files/en-us/web/api/performanceresourcetiming/transfersize/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Update files/en-us/web/api/performanceresourcetiming/connectstart/index.md

* Use ??

* Use ??

* Remove empty space

* Remove space

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Use ??

* Apply suggestions from code review

* Use console.log

* Use console.log

* Use console.log

* Use console.log

* Use console.log

* console.log

* console.log

* Apply suggestions from code review

* Update index.md

* Update index.md

* Update index.md

* Remove useless variable

* Fix typo

* Use findLastIndex()

* Update index.md

* Update index.md

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: rubiesonthesky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants