The wacky world of circular arrays! π
The Wacky World of Circular Arrays
When you think about arrays, you probably have a pretty strict view of what they may look like. It would probably look a little bit like the following where you have a straight row of some sort with a beginning and end:
Now, here is the wacky bit. What if our arrays could actually be treated as a circle where we think of them as starting from anywhere and going on forever and ever and everβ¦and ever?
While this all may sound complicated, there is a mathematical trick that makes thinking about our arrays like this really simple. That trick involves the remainder operator, or the % character you may have seen when fiddling with numbers in JavaScript.
To learn more, check out my latest article on the site, appropriately (and very boringly) called Infinitely Cycle Through an Array. I explain the benefits of thinking about our arrays as a circle and the various JavaScript techniques such as the remainder operator we can use to pull it all off.
Casually Cool Code
Just in case you were curious, this an example of what the code for cycling through a circular array will look like:
Neat, right? This code will print to the console every letter inside myArray. It will print it forever.
Arrays: The Book
If you are looking for a fun and easy-to-follow guide to learn about Arrays in JavaScript, look no further!
Till Next Time
These newsletters have been a bit infrequent, and that is totally my bad. Iβll do my best to be more timely in the future. If you ever have anything youβd like me to consider writing about or just want to chat about anything web development related, drop by the forumsβ¦just like the good old days!
View this email in your browser
Copyright (C) *|CURRENT_YEAR|* *|LIST:COMPANY|*. All rights reserved.
*|IFNOT:ARCHIVE_PAGE|**|LIST:DESCRIPTION|**|END:IF|*
*|IFNOT:ARCHIVE_PAGE|**|HTML:LIST_ADDRESS_HTML|**|END:IF|*
Update Preferences | Unsubscribe
*|IF:REWARDS|* *|HTML:REWARDS|* *|END:IF|*