I have such an array: [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6]
What is the easiest way to return each element in the array from position 6 to 0, where the resulting array looks like this: [1,2,3,4,5,6,7]
These positions in the array can be dynamic, for example, transmission in 4 and 9 should return [11,12,1,2,3,4]
I am wondering if there is a way that does this in the Rails api.
Thank you in advance
EDIT Suppose there are no negative numbers, so array[2..-2] does not work.
Array#splice almost works for this, but if the second position is less than the first, it returns nil .