Skip to content

Instantly share code, notes, and snippets.

@deHelden
Created January 5, 2019 12:02
Show Gist options
  • Save deHelden/d387169b805b6a801694e986a6e5cb69 to your computer and use it in GitHub Desktop.
Save deHelden/d387169b805b6a801694e986a6e5cb69 to your computer and use it in GitHub Desktop.
[Task 4 ] array elements moved 1 position to the left
# 4) Дан целочисленный массив. Осуществить циклический сдвиг элементов массива
# влево на одну позицию.
class ShakingArrayLeft
def initialize
@not_so_greatest_array = Array.new(7){rand(-100...100)}
end
def shake_2_left
primary_element = @not_so_greatest_array[0]
@not_so_greatest_array.each_with_index do |element, index|
if index + 1 < @not_so_greatest_array.length
@not_so_greatest_array[index] = @not_so_greatest_array[index + 1]
else
@not_so_greatest_array[index] = primary_element
end
end
end
end
ShakingArrayLeft.new.shake_2_left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment