I need some clarification: what is expected of my method with regards to offsets bigger than the size of the array?
Am I supposed to default to -1, or last, as the offset?
This isn’t expressly spelt out in the instructions, nor is it in the rotate section of the course material, but when I use the base rotate function and pass 15, it does so.
Let’s say the offset is 5
and the array’s length is 3
. Then you should use 5 % 3
, i.e. 2
, as your offset.
Where is that specified in the problem or within the course material?
Isn’t the end result the same? You end up with the last element (length-1) anyway so why not just set it to arr.length-1?
Sorry for the slow response!
You’re right, the instructions don’t actually spell this out.
Sometimes you’ll end up with the last element, but not always. If the offset is 5
and the array’s length is 4
, then 5 % 4
is 1, which is not length - 1
.