The other day I needed an array that tracked its current position so I can use methods like previous and next. I wrote a simple container to do this. Here is the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
Some of you may have noticed that I am using “typeOf” and not “typeof”. This is because Javascripts existing “typeof” function is broken. Douglas Crockford explains typeof better than I can and also provides a fix. Here is the fix.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
No we are set to use our new Enhanced Array. We can do the following
1 2 3 4 5 6 | |
Handy if you need to track the current location of an array. Enhanced array even goes around the corner both ways. Here is the test code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |