Taken from Execute Program
Write a rotate function. It should move the last element to the beginning of the array. The function should modify the original array.
You’ll need to handle the special case when an array is empty (with a
length
of0
.) When rotate gets an empty array, it should also return an empty array.
Solution
This is the answer I came up with: