Task of Challenge #22
Rotate an array to the right 1 position. E.g. [1, 2, 3] -> [ 3, 1, 2 ] | [1, 2, 4, 6, 3] -> [ 3, 1, 2, 4, 6 ].
reverseArray just creates an empty array
ar2 where the reversed one gets into. A simple
for loop covers the tasks of reversing our array. It does it by decrementing a running index of
i from the
0 and pushing therefore from the last element of the passed array until the first into
for loop, the function just returns your newly reversed array of
If you want to dig deeper into
To get a discount, just subscribe to my newsletter.
The output for the code above is:
Become a Bullet Proof Developer and Seek My Coding Adventures
Upgrade Your Legacy Coding Style With These 6 Modern Ways of Coding