Reputation: 164
I would like to sort the array
order = ['B', 'E', 'A', 'D', 'G', 'C', 'F']
in a way that would return
['F', 'B', 'E', 'A', 'D', 'G', 'C']
In other words, the last element of order
should be moved to the beginning and all other elements should be shifted right one position.
A new array is to be returned (order
is not to be modified). How can I do that?
Upvotes: 2
Views: 46
Reputation: 3057
Assuming your return values are subsequent outputs you can use the rotate
method:
order.rotate(-1)
Upvotes: 2