Skip to content

Instantly share code, notes, and snippets.

@emerak
Last active January 25, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emerak/dcc0f8b2bf4e50572dd3 to your computer and use it in GitHub Desktop.
Save emerak/dcc0f8b2bf4e50572dd3 to your computer and use it in GitHub Desktop.
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