Last active
January 25, 2016 04:21
-
-
Save emerak/dcc0f8b2bf4e50572dd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rotate(arr,index) | |
rotated_array = [] | |
arr.each_with_index do |a,i| | |
new_index = i + index | |
if new_index >= arr.length | |
while new_index >= arr.length do | |
new_index = new_index - arr.length | |
end | |
rotated_array.insert(new_index, a) | |
else | |
rotated_array.insert(new_index, a) | |
end | |
end | |
rotated_array.compact | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment