There is solution to Rotate an array in Ruby programming language
irb(main):001:0> a = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> a.push a.shift
=> [2, 3, 1]
irb(main):003:0>
Put these together in the Array class, and you'll be able to rotate any array easily. class Array
def rotate
push shift
end
end
No comments:
Post a Comment