In the previous article, I talked about iterating over arrays using For ..., For ... of & For ... in loops. You can check it out below:
...
For further actions, you may consider blocking this person and/or reporting abuse
How can you use a variable name "size" for index access? This is a very bad idea. Sure, this is only a short example, however you are seeding the devil into the newcomers minds. Variable naming is crucial. Another thing is that the index variable should be initialized to size-1 when entering the while loop and should be decremented at the end for better readibility. Just my three-- cents.
Hi @rolandcsibrei , thank you for the correction, I appreciate it. But however what I will not appreciate is this statement
however you are seeding the devil into the newcomers minds
. If you want to give someone feedback make it ASK(Actionable, Specific and Kind). Thank you.Sorry, I didn't want to be offending. I apologize.
This has nothing to do with prefixing and suffixing the ++ an -- operators. I am saying that, when you initialize the index to 0, when the condition
(index++ < players.length-1)
is executed the value of index becomes 1 and the first element of the array is skipped.@dovca , I see your point on calling it statements instead of functions, I will correct it to that effect.
The reason for using the
.reverse()
method was explained in the article, just above that section. Seeing this other approach I will, add that to the article and give due credit.Setting the index to 1 will not work for the while loop cause at first iteration the value of index will become 1 because of the increment in the condition. However initializing index to -1 will work.
Thank you.
Awesome refresher. Interesting examples
Thank you @mchardex , I'm glad the article was of help. 👋
Very insightful
Nice one!
Thank you @faruq2 . I am glad you found this useful.
Awesome stuff! Keep them coming.
Thanks for your timely corrections though, I appreciate. @dovca
It was an intention to write it that way to reflect the sample code ;-)